show partically blokced x-axis

1 view (last 30 days)
Hugh
Hugh on 22 Dec 2011
This code shows a partically blocked x-axis, because of the statement "ylim(yl)" trimming the y-axis limit. How do I make the x-axis show? Thanks.
  2 Comments
Walter Roberson
Walter Roberson on 22 Dec 2011
Which code? And please expand on what you mean by "a partially blocked x-axis" ?
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Hugh
Hugh on 22 Dec 2011
My appology, here is the code:
clc;
close all;
clear all;
workspace; % Display workspace panel.
% Generate some sample data
data = 2.5 * sin((1:20)/2) +5;
% Plot the data so we can get the y limits
% so we know where to put gray backgrounds.
% hBars = bar(data);
hBars = plot(data);
yl = ylim;
%set(hBars, 'BarWidth', 1);
x = get(hBars, 'XData');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Define the recession where we'll have a gray background.
recession = data < 4;
hold on;
grayColor = [1 1 1] * 0.8; % Adust to change lightness of the gray.
% Plot gray bars going down.
hBarsDown = bar(yl(1) * recession, ...
'FaceColor', grayColor, 'BarWidth', 1, 'lineStyle', 'none');
% Plot gray bars going Up.
hBarsUp = bar(yl(2) * recession, ...
'FaceColor', grayColor, 'BarWidth', 1, 'lineStyle', 'none');
% Plot main bars.
% hBars = bar(data, 'FaceColor', 'b', 'BarWidth', 1);
axis manual
ylim(yl);
hBars = plot(data);

Sign in to comment.

Answers (3)

Matt Tearle
Matt Tearle on 22 Dec 2011
Quick fix: set(gca,'Layer','top')
Cheap'n'dirty -- that's me :)

Honglei Chen
Honglei Chen on 22 Dec 2011
Hi Hugh,
This is because the axis mode is still 'Auto'. I would suggest you to do the following when adjusting the y axis
axis manual
ylim(yl)
HTH
  1 Comment
Hugh
Hugh on 22 Dec 2011
Honglei, adding axis manual did not work. Here is the full code, your help is much appreciated. - Hugh
clc;
close all;
clear all;
workspace; % Display workspace panel.
% Generate some sample data
data = 2.5 * sin((1:20)/2) +5;
% Plot the data so we can get the y limits
% so we know where to put gray backgrounds.
% hBars = bar(data);
hBars = plot(data);
yl = ylim;
%set(hBars, 'BarWidth', 1);
x = get(hBars, 'XData');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Define the recession where we'll have a gray background.
recession = data < 4;
hold on;
grayColor = [1 1 1] * 0.8; % Adust to change lightness of the gray.
% Plot gray bars going down.
hBarsDown = bar(yl(1) * recession, ...
'FaceColor', grayColor, 'BarWidth', 1, 'lineStyle', 'none');
% Plot gray bars going Up.
hBarsUp = bar(yl(2) * recession, ...
'FaceColor', grayColor, 'BarWidth', 1, 'lineStyle', 'none');
% Plot main bars.
% hBars = bar(data, 'FaceColor', 'b', 'BarWidth', 1);
axis manual
ylim(yl);
hBars = plot(data);

Sign in to comment.


Hugh
Hugh on 22 Dec 2011
Saved me hours. Great, thanks Matt.
  1 Comment
Matt Tearle
Matt Tearle on 22 Dec 2011
Yay. Love it when the cheap tricks work :)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!