how to plot clearer angle yticklabels at whole fractions of 360° (and/or fractions of pi, for radians) in stead of decimal

조회 수: 1 (최근 30일)
I've been looking and trying for a while to plot phase angles with yticklabels matching whole fractions of the angle-domains. Eg: [0 45 90 135 180 ...] for degrees, and [0 pi/4 pi/2 3pi/4 ... ] for radians. And automatically adjusting the fractional resolution according to the min and max phase limits of the concerning plot. Is there an easy way to achieve this, or alternatively, any code that deals with this? Thanks in advance! K

답변 (1개)

Iain
Iain 2014년 10월 20일
편집: Iain 2014년 10월 20일
You can change where the ticks go:
set(axishandle,'YTick', [0 4 6 8 ...] )
You can change the labels as you like:
set(axishandle,'YTickLabel', {'Five' 'Banana' .... } )
  댓글 수: 2
Njiruk Syub
Njiruk Syub 2014년 10월 20일
Yes, I'm familiar with these options, but this method is static, i.e. it lacks the automatic adapting resolution according to the phase range and axis scaling. I work with a lot of phase angle plots (of various ranges) and it would be just to much work to manually adapt the yticklabels each time. I've tried an adapted plot function that includes this:
phase = angle(ydata); ytickmin=floor(min(phase/(pi/4))); ytickmax=ceil(max(phase/(pi/4))); ytickvalues = (ytickmin:ytickmax)*(pi/4); set(gca,'YTick', ytickvalues)
But that is still not satisfying, as it is not flexible for different ranges (it remains problematic when using linspace for the ytickvalues).
K
Iain
Iain 2014년 10월 20일
Ok, what you CAN do is:
1. Determine the X/Y limits of the chart.
2. Figure out where you want your ticks to go. - Say every 8th of the range, rounded to the nearest nice value?
3. Issue the set tick location & label commands.
4. Attach that code to the zoom, pan & rotate callbacks...

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by