因此,Matlab 在三角函数和极坐标图的实际绘制中正确使用弧度。然而令人烦恼的是,它将角轴以度为单位,有什么方法可以改变它吗?
最佳答案
表示角度值的文本对象由 polar
创建其代码(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'
属性。
您可以创建 polar
的修改版本 (用不同的名称保存在用户文件夹中),其中上述部分替换为:
% 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
)被微调以匹配字符串的长度。如果您使用不同的字符串,您可能需要更改该值
这是一个示例结果(我已调用修改后的函数 polar_rad.m
):
theta = 0:.01:2*pi;
rho = sin(theta).^2;
polar_rad(theta, rho)
关于matlab - 将matlab中极坐标图中的轴更改为弧度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28853280/