Separate graph arrows for two y-axes on the matlab

9 ビュー (過去 30 日間)
종영
종영 2024 年 6 月 13 日
移動済み: Angelo Yeo 2024 年 8 月 29 日
In the figure below, the circle arrows are used for two y-axes to indicate which axis the graph follows, how do you do this?

採用された回答

Angelo Yeo
Angelo Yeo 2024 年 6 月 13 日
移動済み: Angelo Yeo 2024 年 8 月 29 日
To add Sai's answer, you can change the color of annotations like below.
EDIT: Fixed the direction of the second arrow as @Aquatris pointed out.
colors = lines(2);
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
dim = [.4 .55 .1 .25];
annotation('ellipse',dim, 'Color', colors(1,:))
annotation('arrow',[dim(1),dim(1)-dim(3)/2],[dim(2)+dim(4)/2,dim(2)+dim(4)/2], 'Color', colors(1,:))
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
dim = [.6 .55 .1 .25];
annotation('ellipse',dim, 'Color', colors(2,:))
annotation('arrow',[dim(1)+dim(3), dim(1)+dim(3)+dim(3)/2],[dim(2)+dim(4)/2,dim(2)+dim(4)/2], 'Color', colors(2,:))
  1 件のコメント
Aquatris
Aquatris 2024 年 6 月 13 日
移動済み: Angelo Yeo 2024 年 8 月 29 日
Red arrow seems to be showing the wrong way Angelo :P

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

その他の回答 (1 件)

sai charan sampara
sai charan sampara 2024 年 6 月 13 日
Hello,
You can try to acheive a similar result by using the "annotations" feature in MATLAB. The following code shows an example for plotting an ellipse and an arrow:
figure
x = linspace(-4,4);
y = x.^3 - 12*x;
plot(x,y)
dim = [.4 .55 .1 .25];
annotation('ellipse',dim)
annotation('arrow',[dim(1),dim(1)-dim(3)/2],[dim(2)+dim(4)/2,dim(2)+dim(4)/2])
The "dim" vector gives the the size and location of the smallest rectangle that encloses the ellipse. The dimensions of the arrow can also be defined separately as per requirement. The values are in normalized units. This can be changed by changing the "Units" property. Here is the link to the documentation for "annotations":

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by