Plot y axis on left and right, displaced x axis

17 views (last 30 days)
Martin on 2 Dec 2015
Answered: Yuebin Zhou on 7 Dec 2015
I want to display on a plot on both sides the y axis labels. I went through some advices found here and it works on the small preview plotted by Matlab. But when I want to maximize the window to my screen size, the x axis are displaced. How can I fix the position of the two x axis, so that they dont move when the size of the window is modified?
This shows the result given by Matlab, when the window is not resized.
This is the result when I resize it to my screen size.
Here is the code that I used to try this:
ax1= gca;
ax1.XLim=[7 22];
ax1.YLim=[0 sum_av_dist_sorted(end,1)];
ax1.FontSize =8.5;
ax1.TitleFontSizeMultiplier = 1.3;
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,'XAxisLocation','bottom','YAxisLocation','right','Color','none');
ax2.FontSize =8.5;
hold on
for i=1:92
% some more code ...
plot(time_bus,dist_bus,'Color',[0.00596 0.40861 0.88284]);
hold on
Thanks for any idea to solve this.

Answers (1)

Yuebin Zhou
Yuebin Zhou on 7 Dec 2015
There is a built-in MATLAB function 'plotyy' which would enable y axes on both sides.

Community Treasure Hunt

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

Start Hunting!