Plot Data with Multiple Scales and further adjusting axes limits

3 ビュー (過去 30 日間)
Vyte Jan
Vyte Jan 2022 年 10 月 26 日
移動済み: Adam Danz 2022 年 10 月 27 日
Hi everyone,
I am having issues plotting two sets of data (with different limits) in the same space, with further adjustments to the y-limits.
My question is very similar to https://uk.mathworks.com/matlabcentral/answers/1571693-plot-lines-with-different-x-axes-on-the-same-matlab-plot, but the method described previously also failed with me data.
My code:
figure
set(gcf,'Color','w') % set the background of figure to white
yyaxis left
x=plot(duration_stats.sd, 'LineWidth', 1, 'Color', 'k')
hold on
yyaxis right
y=plot(duration_stats.spear_r, 'LineWidth',1,'Color','r')
The output graph:
(attached to the question, wont let me upload or add attachments)
Question: how do I further adjust the y-axis, for example, the left yaxis I want to be [0 0.035] and the right yaxis [1 0.096]?
Thanks!

回答 (1 件)

Jeffrey Clark
Jeffrey Clark 2022 年 10 月 27 日
移動済み: Adam Danz 2022 年 10 月 27 日
@Vyte Jan, for your direct question about setting the two ylim(limits) for each of the left and right, do each before switching yyaxis (or by switching back to the appropriate yyaxis again and setting the ylim):
figure
set(gcf,'Color','w') % set the background of figure to white
yyaxis left
x=plot(duration_stats.sd, 'LineWidth', 1, 'Color', 'k')
ylim([0 0.035])
hold on
yyaxis right
y=plot(duration_stats.spear_r, 'LineWidth',1,'Color','r')
set(gca,'YDir','reverse') % the following y limits seem to imply wanting y reversed
ylim([1 0.096]]) % but these may still need to be [0.096 1]
  1 件のコメント
Vyte Jan
Vyte Jan 2022 年 10 月 27 日
移動済み: Adam Danz 2022 年 10 月 27 日
@Jeffrey Clark thank you! I've tried that before and it didn't seem to work, probably because I'd run 'hold on' before ylim. All fixed now :)
(also it wont let me accept your comment as best answer but thank you!)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by