show partically blokced x-axis

1 回表示 (過去 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.
  1 件のコメント
Matt Tearle
Matt Tearle 2011 年 12 月 22 日
Yay. Love it when the cheap tricks work :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by