How to include arrows as pointers of a particular point in plot?
Mostra commenti meno recenti
I have a graph for 3 variables as shown here. I know the saturation point co-ordinates and want arrows of the same color to be pointing them exactly like I have hand drawn in the figure. I tried annotations(arrow) function but it did not work even though I used correct co-ordinates it makes the arrow out of the boundary or maybe I was using it in a wrong way. Please help me if I can draw the arrows at a particular point I need. I would also have to declare 3 set of (x,y) co-odrinates since my main function needs to work simultanously for the three variables.
Code I tried:
plot(T,ih,T,iv,T,sh)
legend('Infected Human','Infected Mosquito','Susceptible Human','Location','east')
xlabel('Time (days)')
ylabel('Population')
x=[39636/40000 39636/40000];
y=[1 180/200];
annotation('arrow',x,y)
Thank you very much in advance.

4 Commenti
the cyclist
il 15 Mag 2020
Can you share the code you used to make the figure, including the "wrong" annotation attempt? That would help us show you what went wrong.
Abhishek Singh
il 15 Mag 2020
Rik
il 15 Mag 2020
It looks like your coordinates are around (1,1), which doesn't match the graph you've drawn. They are also relatively close, so the arrow will be small. Did you zoom in?
Abhishek Singh
il 15 Mag 2020
Risposta accettata
Più risposte (1)
Rik
il 18 Mag 2020
A completely different strategy would be to use the LaTeX interpreter to insert an arrow as a text object:
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y)
text([pi pi*2],[0 0],'\downarrow',...
'FontSize',40,...
'VerticalAlignment','bottom','HorizontalAlignment','center')
20 Commenti
Abhishek Singh
il 18 Mag 2020
Rik
il 18 Mag 2020
'\downarrow' is parsed with (La)TeX to the arrow symbol you see.
Adam Danz
il 18 Mag 2020
I prefer this method to the annotation method since there isn't a need for coordinate transformation.
Here are some additional arrows to try out using Rik's example but they require explicitly setting the interpretter to latex.
text([pi pi*2],[0 0],'\big\downarrow','Interpreter','Latex', ... )
... '\Big\downarrow' ...
... '\bigg\downarrow' ...
... '\Bigg\downarrow' ...
Abhishek Singh
il 18 Mag 2020
Adam Danz
il 18 Mag 2020
Rik's example uses >1 coordinate.
The best way to get that answer is just trying it :)
text(0:.1:1,0:.1:1,'\downarrow')
Abhishek Singh
il 18 Mag 2020
Abhishek Singh
il 18 Mag 2020
Adam Danz
il 18 Mag 2020
% For 1 color used in all arrows
th = text(0:.1:1,0:.1:1,'\downarrow','color','r');
% To define the color of each arrow.
th = text(0:.1:1,0:.1:1,'\downarrow');
colors = jet(11); % Generate the color matrix any way you want.
% The color matrix must have the same number of rows as arrows.
set(th,{'Color'}, mat2cell(colors,ones(size(colors,1),1),3))
Abhishek Singh
il 19 Mag 2020
doc jet
That will show you what jet is.
The matrix is n x 3 for n arrows. The 3 columns are normalized values of [red,green,blue] to produce 1 color per row. If you search the documentation on RGB color vectors you'll get lots of info.
Abhishek Singh
il 19 Mag 2020
Adam Danz
il 19 Mag 2020
Check out the documentation for colormap. jet() is one of more than a dozen color maps. Plus you can create any custom color map you want.
Abhishek Singh
il 22 Mag 2020
Abhishek Singh
il 22 Mag 2020
Adam Danz
il 22 Mag 2020
Glad I could help.
By the way, red, blue green would be
c = [ 1 0 0;
0 0 1;
0 1 0];
Abhishek Singh
il 24 Mag 2020
Rik
il 24 Mag 2020
A colormap is a three-column array. The columns are the intensity of red green and blue on a scale from 0 to 1. Every row is a color in your map.
Given this definition, I don't really understand what you mean.
Abhishek Singh
il 24 Mag 2020
Adam Danz
il 24 Mag 2020
jet(n) produces an nx3 matrix of R,G,B color values. The range of colors is always the same. The only input, n, controls the interval.
I recommended running "doc jet" which explains this. As I mentioned earlier, you can create any color map with an nx3 matrix of values between 0 and 1.
Red is [1 0 0] because it's 100% red, 0% green, 0% blue.
Tongyao
il 23 Ago 2023
Just wanted to add a note here. I attempted to add tilted arrow such as `\nwarrow`. It is part of the Latex default arrow but MATLAB does not support it without additional packages.
Categorie
Scopri di più su Lighting, Transparency, and Shading in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


