plot annotation without normalizing
조회 수: 19 (최근 30일)
이전 댓글 표시
Hello,
I am trying to position my annotation arrows onto a 2D XY plot but it seems that annotation x and y points can only be in normalized units. I would like to place my annotation arrows using the X and Y values that I used for plotting the data. Can someone please help me to convert the data values to normalized values? I have gone through a whole bunch of posts in Matlab and stack overflow but nothing is working. The below code should have worked but it didn't.
"
First, you need to find the position of the axes in normalized figure units. Fortunately, they're set to 'normalized' by default.
axPos = get(gca,'Position'); %# gca gets the handle to the current axes axPos is [xMin,yMin,xExtent,yExtent]
Then, you get the limits, i.e. min and max of the axes.
xMinMax = xlim; yMinMax = ylim; Finally, you can calculate the annotation x and y from the plot x and y.
xAnnotation = axPos(1) + ((xPlot - xMinMax(1))/(xMinMax(2)-xMinMax(1))) * axPos(3); yAnnotation = axPos(2) + ((yPlot - yMinMax(1))/(yMinMax(2)-yMinMax(1))) * axPos(4); Use xAnnotation and yAnnotation as x and y coordinates for your annotation."
So, from this code I understand that "xPlot" and "yPlot" are supposed to represent the databvalues from your plot that you want to convert to normalized unit. However, when I replace the "xPlot" and "yPlot" with specific data value from my plot such as 100 and 200 respectively then my yAnnotation gives a value of 18 and xAnnotation gives a value of 5.3 which is not within the range of 0 to 1!!!!
Can someone please please help me!! Many thanks
댓글 수: 0
답변 (1개)
Walter Roberson
2018년 4월 1일
https://www.mathworks.com/matlabcentral/fileexchange/63760-annotate
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!