필터 지우기
필터 지우기

Display out-of-range points at plot boundary?

조회 수: 13 (최근 30일)
Christopher Hunt
Christopher Hunt 2022년 5월 2일
답변: Prabin Shrestha 2022년 10월 3일
I have a plot with a wide range of y-values. If I plot the entire range I lose a lot of detail I am after in the lower values. Is there a way to set a y-axis maximum, then have points with values above this maximum plotted on the upper y-boundary of the plot? Then I can annotate their actual values. I suppose I could put them in by hand with a graphic editor, but I'm hoping for a more elegant solution. See attached example plot for a rough sketch of what I am imagining. Many thanks in advance.
  댓글 수: 2
Jonas
Jonas 2022년 5월 2일
편집: Jonas 2022년 5월 2일
so what about setting the y values which are greater than your specific y-value equal to your maximum? something like
ylim([0 myMax]); plotY=y; plotY(plotY>myMax)=myMax; plot(x,plotY,.....)?
Matt Butts
Matt Butts 2022년 5월 2일
Do you need this to be dynamic to the y axis range? Could you get away with applying a simple min(...) to your data prior to plotting? You could then use text(...) to add annotations for all points where y == myMaxValue.

댓글을 달려면 로그인하십시오.

답변 (1개)

Prabin Shrestha
Prabin Shrestha 2022년 10월 3일
I workaround this using text (https://www.mathworks.com/help/matlab/ref/text.html) and scatter (https://www.mathworks.com/help/matlab/ref/scatter.html)
plotX: your x-axis values
plotY: your y-axis values
yLimVal: value you want to be limited in y-axis
fontSize: font size you want the text to be
ofBnd = plotY >= yLimVal;
scatter(plotX(ofBnd), ones(sum(ofBnd), 1)*yLimVal)
text(plotX(ofBnd), ones(sum(ofBnd), 1)*(yLimVal-0.1), ...
num2str(plotY(fovObndInd)), 'HorizontalAlignment', 'center',...
'fontWeight', 'bold', 'fontSize', fontSize)
This works for plots with positive y-values but can be extended to any range of y-values. You can experiment with the value you need to decrease (or increase if you use simialr approach in negative y-axis) from y-lim values in (yLimVal-0.1) for proper text location based on your range of y-limits.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by