Annotating an Arrow with in a plot.

12 ビュー (過去 30 日間)
Pappu Murthy
Pappu Murthy 2018 年 3 月 2 日
回答済み: Nirjhar Kumar 2019 年 4 月 2 日
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 件のコメント
Pappu Murthy
Pappu Murthy 2018 年 3 月 4 日
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.

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

採用された回答

Jan
Jan 2018 年 3 月 2 日
編集済み: Jan 2018 年 3 月 2 日
  1 件のコメント
Pappu Murthy
Pappu Murthy 2018 年 3 月 5 日
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.

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

その他の回答 (2 件)

Pappu Murthy
Pappu Murthy 2018 年 3 月 4 日
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 件のコメント
Pappu Murthy
Pappu Murthy 2018 年 3 月 5 日
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 2018 年 3 月 5 日
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%.

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


Nirjhar Kumar
Nirjhar Kumar 2019 年 4 月 2 日
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;

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by