Annotating an Arrow with in a plot.

15 visualizaciones (últimos 30 días)
Pappu Murthy
Pappu Murthy el 2 de Mzo. de 2018
Respondida: Nirjhar Kumar el 2 de Abr. de 2019
I am trying to use the annotation function to show an arrow on my plot like ar = annotation('arrow'..) I know the location where I want the arrow to start the x and y coordinates in my data units. However, the documentation says I can only specify in normalized units which are between 0 and 1 for any figure. But this will not work for me. So what is a work around so that I can put the arrow exactly at a point specified by userdata.
  1 comentario
Pappu Murthy
Pappu Murthy el 4 de Mzo. de 2018
When I first create the figure it looks like this: picture file one.png
I click on plot tools icon it then fills my screen and i see it full size but my arrows are all badly placed now.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 2 de Mzo. de 2018
Editada: Jan el 2 de Mzo. de 2018
  1 comentario
Pappu Murthy
Pappu Murthy el 5 de Mzo. de 2018
I tried the FEX function it works fine for me. But again When I change the plots to fullscreen mode with plottools on the arrows get displaced badly.

Iniciar sesión para comentar.

Más respuestas (2)

Pappu Murthy
Pappu Murthy el 4 de Mzo. de 2018
the link helped me solve the problem partially. When I click on maximize the window with plot tools, all the arrow positions are screwed up. Or if I place the arrows after I adjust the figure to fit the window and click on plot tools, then the arrows are placed correctly. However, I have no control to make the figure full screen and with plot tools enabled without manually clicking the options. How do i overcome this?
  3 comentarios
Pappu Murthy
Pappu Murthy el 5 de Mzo. de 2018
I tried this it seems to work the figure occupied the full screen and arrows looked right. But the moment I click on the "plot tools" button the picture becomes somewhat smaller due to the placement of all the plot tool components. While 99% of the figure is still okay, the arrows I placed are no longer properly positioned. Why? May be it is a Matlab bug. So problem is the entire figure is not gracefully scalable.
Pappu Murthy
Pappu Murthy el 5 de Mzo. de 2018
Some nothing seems to work ok with my specific case. If I create a sample case it seems to work. So what I finally tried after searching through Matlab helpfile is to include a line "plottools('on') before I create my 'arrows' and it worked like charm. So I am going to close this question. Thanks for all the help provided. They did solve most of the problem if not 100%.

Iniciar sesión para comentar.


Nirjhar Kumar
Nirjhar Kumar el 2 de Abr. de 2019
open a figure and Just pass the position of x data's to the below function
function obj = dataArrow2(xpos)
%This function will draw an arrow on the plot for the specified x data position .
%Eg:
% plot(0:0.001:10,sin(0:0.001:10))
% dataArrow2([3000 6000 9000])
handles=findall(0,'type','figure');
for fig_cnt= 1:1:length(handles)
figure(handles(fig_cnt,1))
ax=handles(fig_cnt,1);
% hLeg=findobj(handles(fig_cnt,1),'type','legend');
% set(hLeg,'visible','off')
axObjs=findobj(handles(1,1),'type','Axes');%axObjs = ax.Children;
dataObjs = axObjs.Children;
oldunits = get(axObjs, 'Units');
set(axObjs, 'Units', 'Inches');
axpos = axObjs.Position
set(ax, 'Units', oldunits);
oldunits = get(handles, 'Units');
set(handles, 'Units', 'Inches');
figpos= handles.Position
set(handles, 'Units', oldunits);
% set(hLeg,'visible','off')
%get axes drawing area in data units
ax_xlim = ax.CurrentAxes.XLim;
ax_ylim = ax.CurrentAxes.YLim;
ax_per_xdata = axpos(3) ./ diff(ax_xlim);
ax_per_ydata = axpos(4) ./ diff(ax_ylim);
for i=1:1:length(dataObjs)
Xdata = dataObjs(i).XData;
Ydata = dataObjs(i).YData;
%these are figure-relative
for j=1:1:length(xpos)
Xpixels = (Xdata([xpos(j) xpos(j)+1]) - ax_xlim(1)).* ax_per_xdata+axpos(1);
%if set(gca,'xdir','reverse') is used
%Xpixels = -(Xdata([pos pos+1]) - ax_xlim(1)).* ax_per_xdata+axpos(3)+axpos(1);
Ypixels = (Ydata([xpos(j) xpos(j)+1]) - ax_ylim(1)).* ax_per_ydata+axpos(2);
%if set(gca,'ydir','reverse') is used
%Ypixels = -(Ydata([pos pos+1]) - ax_ylim(1)).* ax_per_ydata+axpos(2)+axpos(4);
annotation('arrow', Xpixels/figpos(3), Ypixels/figpos(4));
end;
obj = 1;
end
end;

Community Treasure Hunt

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

Start Hunting!

Translated by