Hi, I am trying to build a plot with 2 y axis and want to assign different shapes to each variable and legend as well but facing error:
A = 2*rand(10,1);
B = 20*rand(10,1);
C = 30*rand(10,1);
grid on
box on
hold on
x = 1:10;
y = A;
yyaxis left
plot(x,y,'p')
z = [B C];
yyaxis right
plot(x,z,'^','o')

 採用された回答

Voss
Voss 2023 年 3 月 10 日

1 投票

A = 2*rand(10,1);
B = 20*rand(10,1);
C = 30*rand(10,1);
grid on
box on
hold on
x = 1:10;
y = A;
yyaxis left
plot(x,y,'p')
yyaxis right
plot(x,B,'^',x,C,'o')

4 件のコメント

MattC
MattC 2023 年 3 月 10 日
編集済み: MattC 2023 年 3 月 10 日
How do I add a label and change color for this plot?
Voss
Voss 2023 年 3 月 10 日
編集済み: Voss 2023 年 3 月 10 日
A label like a legend? Or an axis label? Here's both, along with changing the line colors:
A = 2*rand(10,1);
B = 20*rand(10,1);
C = 30*rand(10,1);
grid on
box on
hold on
x = 1:10;
y = A;
yyaxis left
plot(x,y,'pr') % include colors in linespec
ylabel('Left Y')
yyaxis right
plot(x,B,'^g',x,C,'ob')
xlabel('X')
ylabel('Right Y')
legend('A','B','C')
MattC
MattC 2023 年 3 月 10 日
I am trying to add this custom 0.7/0.7/0.2 color for point on right y axis
Voss
Voss 2023 年 3 月 10 日
A = 2*rand(10,1);
B = 20*rand(10,1);
C = 30*rand(10,1);
grid on
box on
hold on
x = 1:10;
y = A;
yyaxis left
h = plot(x(1:end-1),y(1:end-1),'pr');
plot(x(end),A(end),'p','Color',[0.7 0.7 0.2])
ylabel('Left Y')
yyaxis right
h = [h; plot(x(1:end-1),B(1:end-1),'^g',x(1:end-1),C(1:end-1),'ob')];
plot(x(end),B(end),'^',x(end),C(end),'o','Color',[0.7 0.7 0.2])
xlabel('X')
ylabel('Right Y')
legend(h,'A','B','C')

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

その他の回答 (0 件)

カテゴリ

製品

タグ

質問済み:

2023 年 3 月 9 日

コメント済み:

2023 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by