I have a problem adding a second y-axis; all solutions point out that I need another data set to have a second y-axis. However, I want to have two y-axis for a single point while the x-axis is the same.
For instance;
point=(3,6), and I want to show that on the right y-axis side, the point (3,6) has a 0.5 value, so the general notation could be as (x,y1,y2)=(3,6,0.5)
first data
For example;
x=[3,5,6,8,11]
y1=[6,7,9,14,17]
I want right y axis to be
y2=[0.5,2,5,7,11]
.

3 件のコメント

dpb
dpb 2022 年 10 月 27 日
You can put a single point on the RH axis -- but plot or line won't show anything for a single point -- use scatter instead (or be sure to put a specific marker in the linestyle triplet location if do use plot).
But, it's not at all clear what you actually want here -- what's "point=(3,6), and I want to show that on the right y-axis side, the point (3,6) has a 0.5 value" really mean? The point (3,6) defines an x/y value on the two axes at that location; how can it then have the value of 0.5? And, then, what is the purpose/need of the y2 vector?
This is all very confusing as to actual intent.
Gunay Gazaloglu
Gunay Gazaloglu 2022 年 10 月 27 日
編集済み: Gunay Gazaloglu 2022 年 10 月 27 日
You have a single point which has two dimesions (x and y) or (x,y)
x (horizontal axis)
y(vertical axis)
Then (3,6) is a point on that graph
after that I simply ask to have another y axis at the right side and .So your existing point (3,6) will have a value also at the right y axis.
I hope it is more understandable for you now.This is simplest way that ı can explain it...
Torsten
Torsten 2022 年 10 月 27 日
I think what you need is plot3, not a second y-axis.

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

 採用された回答

Alberto Cuadra Lara
Alberto Cuadra Lara 2022 年 10 月 27 日

0 投票

Hello Gunay,
Use yyaxis, here is a simple example.
Best,
Alberto
x = [3,5,6,8,11];
y1 = [6,7,9,14,17];
y2 = [0.5,2,5,7,11];
hold on; axis tight
plot(x, y1);
yyaxis right;
plot(x, y2);

3 件のコメント

Gunay Gazaloglu
Gunay Gazaloglu 2022 年 10 月 27 日
編集済み: Gunay Gazaloglu 2022 年 10 月 27 日
Thank you but this is not what I exactly asked. There should be one line which is blue here and right y axis should be according to that blue line.
For example check the point (5,7) on blue line, corresponding right y axis is around 1.75 but it should be 2.
Alberto Cuadra Lara
Alberto Cuadra Lara 2022 年 10 月 27 日
編集済み: Alberto Cuadra Lara 2022 年 10 月 27 日
Hello Gunay,
If you want a line with data that is not proportional to each other, i.e., different scales, you will need to set a piecewise scale distribution. This can be done, for example changing yticks values and yticklabels.
% Data
x = [3,5,6,8,11];
y1 = [6,7,9,14,17];
y2 = [0.5,2,5,7,11];
% Plot configuration
colororder({'k','k'})
hold on; axis tight
% Plot (left)
plot(x, y1);
% Plot (right)
yyaxis right;
plot(x, y1);
% Change yticks (right)
set(gca, 'YTick', y1, 'YTickLabel', y2)
Gunay Gazaloglu
Gunay Gazaloglu 2022 年 10 月 27 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by