I plot data using plotyy, then after adding several other data series to the plot, i need to readjust the axis limits to have them all in range, but when I do, the limits only occupy a small portion of the plot as seen in the image
이전 댓글 표시

The image below shows the problem that I am getting. When i submit the code to change the axis limit for x, there is no issue with the graph, but when i send the code to adjust the left y axis, it shrinks the size as shown below. The data is in the range, but it does not get spread out amongst the full plot area. Any ideas?
Heres the code I use to adjust the axis:
%Plot both axis's
[hax, h(1,i), h(2,i)] = plotyy(X_Data(:,i), Y1_Data(:,i), X_Data(:,i), Y2_Data(:,i));
%Set line color and marker
set(h(1,i), 'marker', 'o');
set(h(1,i), 'color', ColorSet(i,:));
set(h(2,i), 'marker', 'x');
set(h(2,i), 'color', ColorSet((ColorVariation - i),:));
%Set axis limits
xlim(hax(1), [xmin xmax])
xlim(hax(2), [xmin xmax])
ylim(hax(1), [y1min y1max])
After running this initial data, I add additional plots to the same one to have for example 5 lines corresponding to the left y axis and the right y axis. But I need to be able to adjust the limits to see the data accordingly. Thanks!
댓글 수: 3
i is undefined in the code snippet posted so I'm guessing you're in a loop or somesuch...ergo, it would appear the actual data aren't in synch with the axis being displayed; perhaps what you've done is overwritten the hax array from a previous call and set the wrong handle axis which is on top but there's another underneath or the like.
We need a complete (but minimal) piece of code including data that can run that reproduces the issue. Details like setting markers, colors, etc., etc., are fluff; pare it down to the bare bones and make sure you can run it locally as it stands without other existing figures, axes, data, etc. If you build that you may well discover where you made the gaff as a side benefit! :)
Abhisek Roy
2016년 2월 4일
Hi Ryan,
It looks like at some point in the code the 'XTick' for 'hax(1)' is set as [3.75 3.8 3.85 3.9 3.95] as those are the only ticks which are being marked in the plot and also from the figure, I noticed that the first plot(hax(1)) i.e. the blue plot is spanned through-out the plot window. So, I think in the code somewhere XTicks are defined. Is this the complete code which is giving you the above plot?
dpb
2016년 2월 4일
Good catch @Abhisek...also note that while the code snippet says
set(h(1,i), 'marker', 'o');
set(h(2,i), 'marker', 'x');
that the actual markers are reversed from what one would expect given the plotyy call
[hax, h(1,i), h(2,i)] = plotyy(...
the column 1 line handles should be associated with the LH axis and vice versa but by the axis color they're reversed. Things have gotten jumbled, clearly.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!