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

1 view (last 30 days)
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!
dpb on 4 Feb 2016
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.

Sign in to comment.

Answers (0)


Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!