show partically blokced x-axis

1 visualización (últimos 30 días)
Hugh
Hugh el 22 de Dic. de 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 comentarios
Walter Roberson
Walter Roberson el 22 de Dic. de 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 el 22 de Dic. de 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);

Iniciar sesión para comentar.

Respuestas (3)

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

Honglei Chen
Honglei Chen el 22 de Dic. de 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 comentario
Hugh
Hugh el 22 de Dic. de 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);

Iniciar sesión para comentar.


Hugh
Hugh el 22 de Dic. de 2011
Saved me hours. Great, thanks Matt.
  1 comentario
Matt Tearle
Matt Tearle el 22 de Dic. de 2011
Yay. Love it when the cheap tricks work :)

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by