One Plot two different y-axis, how to scale second y-axis?

How can I plot one data set with two different scales, where the second (right) y-axis has no linear relation to the left one.
I only want to see the blue dots where instead the second (right) y-axis is scaled this points.
To reverse the axis I used set(gca, 'YDir','reverse') so far though it seems with yyaxis this issue is not solvable.
How can I do this?

3 件のコメント

jonas
jonas 2018 年 9 月 15 日
Should it have the same limits as the left one but reversed?
MPi
MPi 2018 年 9 月 15 日
E.g. the orange dot at x = 0 is around ~157 instead showing the orange dot I want to see only the blue one and the orange axis should be scaled due to this. Means the orange axis should start with 157 for example.
Or for the second point at x = 100 where blue y = 100, I don't want to see a orange don't instead I want the second axis scaled to that. Though the hard thing is, that there is no linear relation between the left and the right axis.
jonas
jonas 2018 年 9 月 15 日
編集済み: jonas 2018 年 9 月 15 日
OK, I think I get it. You want the y-value of the orange dots to be represented on the second yaxis as ticks? Bear in mind, the right yaxis will still be linear, just showing uneven ticks (?)

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

 採用された回答

jonas
jonas 2018 年 9 月 15 日
編集済み: jonas 2018 年 9 月 15 日

0 投票

Probably not what you want, but perhaps one step closer:
x=[0 100 300 500 800 800]
y1=[0 100 180 200 255 260]
y2=[155 124 115 79 42 40]
yyaxis left
plot(x,y1,'o')
yyaxis right
plot(x,y2,'o','color','none');
set(gca,'ytick',flip(y2))
set(gca,'ylim',[min(y2) max(y2)])
set(gca, 'YDir','reverse')

10 件のコメント

MPi
MPi 2018 年 9 月 15 日
E.g. the data for the right axis are calculated as following...
yy = (((2.*x).*(1000*10^-6)./sqrt(2)).^2).*3000;
Instead of showing the new result I just want the right axis scaled to the data points from y.
jonas
jonas 2018 年 9 月 15 日
編集済み: jonas 2018 年 9 月 15 日
I updated the solution. I'm still not enturely sure what you mean by "scaled to the points from y" Are you talking about an actual non-linear scale?
MPi
MPi 2018 年 9 月 15 日
When I plot your code, I want the right axis match with the blue dots. That means at x=0,y=0, I want yy = 155 and so on.
jonas
jonas 2018 年 9 月 15 日
編集済み: jonas 2018 年 9 月 15 日
I added another line that changed the yyaxis limits. Do you want the tick on 124 to exactly match the vertical location of the blue dot?
You can of course always fake it by adding perfectly vertically aligned ticks on the yyaxis and then change their yticklabels to match with your desired values.
MPi
MPi 2018 年 9 月 15 日
Yes, because now I just see the empty ticks, e.g. I also want to match 42 and 40 with 255 and 260.
In the end it would be nice to have a full scale e.g. from 155 to 30 with just sub ticks at the blue dots.
jonas
jonas 2018 年 9 月 15 日
Matching 42 and 40 with 255 and 260 is also easy, just add:
set(gca,'ylim',[min(y1) max(y1)])
below the first plot. Matching the other ones are more difficult, as you'd need a very peculiar non-linear type of axis. I'm not sure this is what you want.
MPi
MPi 2018 年 9 月 15 日
Ah, sure that works for me!
Thank you!
jonas
jonas 2018 年 9 月 15 日
編集済み: jonas 2018 年 9 月 15 日
Great!
Here's a hacky/buggy solution if you want to fake the axis labels so as to match perfectly.
x=[0 100 300 500 800 800]
y=[0 100 180 200 255 260]
yyticklabels=[155 124 115 79 42 40]
yyaxis left
plot(x,y,'o')
set(gca,'ylim',[min(y) max(y)])
yyaxis right
plot(x,y,'o','color','none');
set(gca,'ylim',[min(y) max(y)])
set(gca,'ytick',y,'yticklabels',num2str(yyticklabels'))
MPi
MPi 2018 年 9 月 15 日
This hack works perfectly fine for me! Thank you again!
jonas
jonas 2018 年 9 月 15 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

質問済み:

MPi
2018 年 9 月 15 日

コメント済み:

2018 年 9 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by