在Matlab中将极坐标图中的轴更改为弧度
因此,matlab正确地将弧度用于三角函数和极坐标图的实际绘制中.但是很烦人的是,它把角轴放在度数上,有什么办法可以改变吗?
So matlab rightfully uses radians for trigonometric functions and in the actual plotting of polar plots. However annoyingly it puts the angular axis in degrees, is there any way to change this?
表示角度值的文本对象由polar
函数在其代码的以下部分(Matlab R2010b)中创建:
The text objects representing angular values are created by the polar
function in the following section of its code (Matlab R2010b):
% annotate spokes in degrees
rt = 1.1 * rmax;
for i = 1 : length(th)
text(rt * cst(i), rt * snt(i), int2str(i * 30),...
'HorizontalAlignment', 'center', ...
'HandleVisibility', 'off', 'Parent', cax);
if i == length(th)
loc = int2str(0);
else
loc = int2str(180 + i * 30);
end
text(-rt * cst(i), -rt * snt(i), loc, 'HorizontalAlignment', 'center', ...
'HandleVisibility', 'off', 'Parent', cax);
end
由于代码将'HandleVisibility'
设置为'off'
,因此这些文本对象在函数外部不可见,因此您无法修改其'String'
属性.
Since 'HandleVisibility'
is set to 'off'
by the code, those text objects are not visible from outside the function, and thus you can't modify their 'String'
property.
您可以创建
You can create a modified version of polar
(save it with a different name, in a user folder) in which the above section is replaced by this:
% annotate spokes in degrees
rt = 1.13 * rmax;
text_strings = {'\pi/6' '\pi/3' '\pi/2' '2\pi/3' '5\pi/6' '\pi' ...
'7\pi/6' '4\pi/3' '3\pi/2' '5\pi/3' '11\pi/6' '0'};
for i = 1 : length(th)
text(rt * cst(i), rt * snt(i), text_strings{i}, ...
'HorizontalAlignment', 'center', ...
'HandleVisibility', 'off', 'Parent', cax);
text(-rt * cst(i), -rt * snt(i), text_strings{i+6}, ...
'HorizontalAlignment', 'center', ...
'HandleVisibility', 'off', 'Parent', cax);
end
对此代码的评论:
- 也许您希望在不简化分数的情况下定义
text_strings
(即'2\pi/6'
而不是'\pi/3'
等). - 对第一行中的
1.13
(最初为1.1
)进行微调以匹配字符串的长度.您可能需要更改该值,因为您使用的是不同的字符串
- Maybe you prefer to define
text_strings
without simplifying the fractions (i.e.'2\pi/6'
instead of'\pi/3'
etc). - The
1.13
in the first line (originally1.1
) is fine-tuned to match the length of the strings. You may need to change that value is you use different strings
这是一个示例结果(我将其称为修改后的函数polar_rad.m
):
Here's an example result (I've called the modified function polar_rad.m
):
theta = 0:.01:2*pi;
rho = sin(theta).^2;
polar_rad(theta, rho)