Plotyy - overlapping bars and horizontal lines

2 visualizzazioni (ultimi 30 giorni)
Chameleon17
Chameleon17 il 18 Apr 2016
Good Afternoon,
I am trying to plot some data in a bar chart but I require two y axis for scale reasons and am thus using plotyy. I have come across two problems though. 1. my bars are overlapping, I have been digging around for solutions and have found one that separates them, but it still looks messy, it isn't uniform across all the bars, is there another way? 2. I have plotted a horizontal line from y1 across the plot, but I need to also plot a separate horizontal line from the y2 axis, I'm a bit stumped as to how I do this, I did not indicate y1 when I plotted the first line.
% Variables
offset = (X(2)-X(1))/8;
width = (X(2)-X(1))/4;
% Plot
[aX, h1, h2] = plotyy(X-offset,y1,X+offset,y2, @(X,y) bar(X,y,width), @(X,y) bar(X,y,width));
set(aX(1),'YLim',[0 23])
set(aX(1),'YTick',[0:1:23])
set(aX(2),'YLim',[0 25.25])
set(aX(2),'YTick',[0:1:25.25])
set(aX(1),'box','off')
set(aX(1),'xlim',[0 52]);
set(aX(1),'Xtick',[0:1:51])
set(aX(2),'xlim',[0 51]);
set(aX(2),'Xtick',[0:1:51])
set(h1,'FaceColor','red');
set(h2,'FaceColor','blue');
hold on
plot(get(gca,'xlim'), [ten ten]);
hold off

Risposte (0)

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by