show partically blokced x-axis

2 次查看(过去 30 天)
Hugh
Hugh 2011-12-22
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 个评论
Walter Roberson
Walter Roberson 2011-12-22
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 2011-12-22
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);

请先登录,再进行评论。

回答(3 个)

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

Honglei Chen
Honglei Chen 2011-12-22
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 个评论
Hugh
Hugh 2011-12-22
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);

请先登录,再进行评论。


Hugh
Hugh 2011-12-22
Saved me hours. Great, thanks Matt.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by