How to add arrows in plotted curves to point corresponding axis?

44 views (last 30 days)
Hello community,
I have the following plot that contains two separate yy' axes. One of the plotted curves corresponds to the right axis and the others to the left.
Is there an automatic way to create arrows on the curves that point towards the direction of the corresponding axis? (As seen in the figure which I drew below)
I have read some instructions on creating arrows, but not as in this situation. Also, the curves won't be fixed so the location of the arrows will have to adjust when I run the code with different input.
Thanks in advance,
Giannis

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 12 Jun 2020
There are a number of arrow-contributions on the file exchange. These two are my favourites: arrow3, arrow, other contributions might now be more up-to-date. You could do something like take the data-point closest to half-way between xmin and xmax, and then subtract or add a suitable fraction of the data-range to that and then plot the arrow in your desired direction from that point. That might become cludgy, since lines might intersect close to there leading to multiple nearly overlapping arrows at the same location. But maybe you have enough luck to get this to work most of the time.
Wouldn't it be OK (or preferable) to plot the curves coding in colour which y-axis they refer to and use the line-style to separate the different curves? You might even use different hues of blues and reds for carrying the left/right-axis information to make the plot more graphically pleasing. (It is just that I found it a bit confusing that the red curve in your example-image above were connected with the blue axis...)
HTH
  2 Comments
Giannis Zavos
Giannis Zavos on 15 Jun 2020
Edited: Giannis Zavos on 15 Jun 2020
Thank you Bjorn for the quick reply. I will look at the functions you suggested in more detail. Using line styles for each axis won't help because there might be more than one curves for each axis. (The axis were painted red and blue automatically, I did not select that).
Bjorn Gustavsson
Bjorn Gustavsson on 15 Jun 2020
Giannis, my idea was to use the colours of the axis for the colour of the curves, then use line-styles to encode the different curves inside each set. Maybe this example is a better illustration:
X = linspace(0,1);
P = peaks(numel(X));
Y1 = P(:,[40 50 70])';
Y2 = P([40 50 65],:)*12;
lstl = {'-','--','-.'};
clrs1 = [0 0 .8;0 0 1;0 0.3 1];
clrs2 = [0 .6 0;0 .8 0 ;0 1 0];
clf
for i1 = 1:3,
[yyax,yyph1(i1),yyph2(i1)] = plotyy(X,Y1(i1,:),X,Y2(i1,:));
hold on
set(yyax(1),'fontsize',12)
set(yyax(2),'fontsize',12)
set(yyph1(i1),'linestyle',lstl{i1},'linewidth',2,'color',clrs1(i1,:))
set(yyph2(i1),'linestyle',lstl{i1},'linewidth',2,'color',clrs2(i1,:))
end
legend([yyph1(:);yyph2(:)],'1a','2a','3a','1b','2b','3b','location','northwest')
Maybe it is still obvious that the curves with blue hues are connected to the blue axis and the green ones to the green axis. Maybe you can use only a combination of line-styles and line-widths if the colour becomes too vague. You can also set the axes-color to some more distinct hues, here perhaps reds would be better than greens.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!