How do I change the yaxis exponent when using a double y-axis plot?

118 ビュー (過去 30 日間)
Pieter Spruijt
Pieter Spruijt 2017 年 12 月 21 日
コメント済み: Ankit Labh 2023 年 5 月 18 日
When use a plot with a y-axis on the left and a y-axis on the right, I can't figure out how to change the exponent of one y-axis. For example, when using the following code:
x = [1 2 3];
y1 = [2 6 4; 3 5 4; 5 7 8];
y2 = 100*[5 5 3; 3 4 7; 5 6 3];
figure
yyaxis left
plot(x,y1)
yyaxis right
plot(x,y2)
ax = gca;
yyaxis left
ax.YDir = 'reverse';
yyaxis right
ax.YAxis.Exponent = 3;
So I can change the direction of the left axis, but when I change the exponent of the right axis, I get the following error: "Expected one output from a curly brace or dot indexing expression, but there were 2 results. Error in test line 19) ax.YAxis.Exponent = 3;"

回答 (1 件)

Ramnarayan Krishnamurthy
Ramnarayan Krishnamurthy 2017 年 12 月 28 日
Try setting the exponent as follows:
ax.YAxis(2).Exponent=3;
instead of ax.YAxis.Exponent = 3;
This sets the exponent of the second Y Axis (the one to the right) to 3.
  2 件のコメント
Christof Tschannen
Christof Tschannen 2022 年 7 月 26 日
I am so gratefull for that comment! I was looking for a long time for a solution of having two y-axis, one logarithmic, the other linear and I could not get rid of the scientific notation on the logarithmic y-axis.
Btw, I was using this command that I picked up in another forum post and added the axis indicator to it:
ax=gca
ax.YAxis(1).TickLabels = compose('%g', ax.YAxis(1).TickValues);
The code worked when I had only one axis, but with two I always got an error. With the specification (1) it finally worked :)
Again, thanks a lot!
Ankit Labh
Ankit Labh 2023 年 5 月 18 日
Well, even this (ax.YAxis(2).Exponent=-3;) isn't working for me.

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by