Theta marked in radians for ezpolar?
조회 수: 10 (최근 30일)
이전 댓글 표시
I have read and successfully converted the default degree measure to radians for a polarplot. The same procedure does not appear to work with ezpolar. How do you get theta marked in radians for ezplot?
This code has the desired effect:
theta=linspace(0, 2*pi, 100);
rho=1+3/2*sin(2*theta);
polarplot(theta, rho)
ax=gca;
ax.ThetaAxisUnits='radians';
This code leaves the theta markings in degrees
ezpolar(@(t) 1+3/2*sin(2*t), [0, 2*pi])
ax=gca;
ax.ThetaAxisUnits='radians'
Prefacing the latter with polaraxes() gets both units.
Why, why, why is the expected input for both polarplot and ezpolar in radians (seems sensible as a calculus instructor), but the default theta marking in degrees???
댓글 수: 0
채택된 답변
Adam Danz
2020년 8월 24일
편집: Adam Danz
2020년 8월 24일
polarplot uses polaraxes whereas expolar creates a pseudo-polar-plot on regular Cartesian axes. The ThetaAxisUnits property is not available with Cartesian axes. Instead, the theta ticks are added as text objects.
I recommend using polaraxes unless you have a very good reason not to.
To convert the theta ticks in the expolar plot to radians, you'll have to identify which text objects are the theta ticks and then convert them to radians.
This demo uses fractions to label the theta ticks.
ezpolar(@(t) 1+3/2*sin(2*t), [0, 2*pi])
ax=gca;
% Get all text objects
h = findall(ax, 'type', 'text');
% Loop through each text object. If it appears to be a
% theta tick label, convert it to radians.
existingTicks = 0:30:360; % List existing theta ticks
existingTickStr = strsplit(num2str(existingTicks));
for i = 1:numel(h)
if ismember(h(i).String, existingTickStr)
[num,denom] = rat(str2double(h(i).String)/180);
if num==0 || denom==1
h(i).String = sprintf('%d\\pi', num/denom);
else
h(i).String = sprintf('^{%d}/_{%d} \\pi', num, denom);
end
end
end
For more simpler decimal labels, replace the inside of the loop with,
if ismember(h(i).String, existingTickStr)
h(i).String = sprintf('%.2f',str2double(h(i).String)*pi/180);
end
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!