matlabploar,如何在Matlab极坐标polar绘图上增加刻度单位

matlabploar,如何在Matlab极坐标polar绘图上增加刻度单位如何在Matlab极坐标polar绘图上增加刻度单位
⼀直以来,想在极坐标上⾯增加刻度,不知道该如何更改,经常是⼿动加⼊,费时费⼒。今天突然想起来为何不能通过修改Matlab的已知源代码,去更改呢?百度了之后,到了以下的⽂章:
先不看⽂章,先来看Matlab默认绘制出来的效果图:
艳情故事命令如下:
t = 0 : .01 : 2 * pi;
polar(t, sin(2 * t) .* cos(2 * t), '--r');
那么问题来了,我想在0到360上⾯增加度的标记,即“°”,在0.1,0.2……上⾯增加微⽶标记,即μm。那么我们查Maltab的代码。在命令窗⼝敲出polar,然后双击选中,右键选择打开该命令。
打开后,到第153(int2str(i*30))和161(loc)⾏,即为我们想要增加的度的标⽰部分:
更改为如下程序:
第⼆部分的修改,到第136⾏:
修改为:
⼤功告成。注意,我们尽量不去修改Matlab原始的代码,所以我们这⾥将整个修改后的程序另存为:Mypolar.m。下⾯我们看⼀下修改后的绘图效果:
命令如下:
t = 0 : .01 : 2 * pi;
Mypolar(t, sin(2 * t) .* cos(2 * t), '--r');
同理,我们还可以⽤类似的⽅法修改相应代码,得到我们想要的效果。
最后,还是那句话:多看Matlab Help!多看Matlab
Help!多看Matlab
Help!
参考:
杨宗胜matlab极坐标图改变坐标系标注
作者
这两个命令的⾓度是定死的,没有提供任何接⼝去修改。你⼀定要改,就只能改这两个命令的源代码了
打开polar.m后可以到下⾯这段语句% plot spokes
th =
(1:6)*2*pi/12;
cst =
cos(th); snt = sin(th);
cs = [-cst;
cst];
sn = [-snt;
snt];
line(rmax*cs,rmax*sn,'linestyle',ls,'color',tc,'linewidth',1,...
'handlevisibility','off','parent',cax)把th改成别的值就可以绘制不同的⾓度了,⽐如改成th
= (1:4)*2*pi/8;就是45度的分割线了。当然下⾯还要继续改显⽰的度数% 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把两个30全部改为45即可。---------------------------------------------------------------------------------
t = 0:.01:2*pi;
polar(t,sin(2*t).*cos(2*t),'--r')
set(gca,'xdir','reverse')
次函数可简单的将x轴反向。。。
-
--------------------------------------------------------------------------------
基本上,
若是使⽤polar画图好像就⽆法更改其相关属性!虽然可以使⽤set(gca,...)更改其相关属性,
但你会发现并没有更动! 原因为误认那些标⽰为'XTickLabel',
其实都不是,
切⼊polar.m看仔细就会发现其为text产⽣,
所以外部更改都⽆效!我试了直接更改polar.m来实现即可% draw radial circles
c82 = cos(82*pi/180);
s82 = sin(82*pi/180);
rinc = (rmax-rmin)/rticks;
ppp=(rmin+rinc):rinc:rmax; [color=red]ppp=fliplr(ppp);
iip=0;[/color]
for
i=(rmin+rinc):rinc:rmax
hhh =
脉管舒plot(xunit*i,yunit*i,ls,'color',tc,'linewidth',1,...
'handlevisibility','off');[color=red] iip=iip+1;
[/color] text((i+rinc/20)*c82,(i+rinc/20)*s82,
...
[' '
num2str([color=red]ppp(iip[/color][color=red])[/color])],'verticalalignment','bottom',...
'handlevisibility','off')
end
set(hhh,'linestyle','-') %
Make outer circle solid
------------------------
t=0:.01:2*pi; hh=polar77(20*t,200*sin(2*t).*cos(2*t),'--r');
-----------------------
此⽅法提供者应该是个⾼⼿,可惜我没有尝试成功
---------------------------------------------------------------------------------
官⽹上提供polarlabels.m
polarlabels([0:360]*pi/180,abs(sin([0:360]*pi/180))*10,'b',-90,10)
可实现⼀些简单的变化。。。似乎实现的功能不够强⼤
-
--------------------------------------------------------------------------------
有⼈提议polarhg.m
polarhg(theta,rho,'tdir','clockwise','rlim',[0 10], ...'rtick',[0 3
6 9],'tstep',45,'torig','up', 'color','m','linestyle',':')。这样整个图形就旋转了90度。------------------另外,polarhg还有个问题,当运⾏,⽐如,>> theta =
0:pi/5:pi;
>> rho =
10*rand(size(theta));
>> h =
polarhg(theta,rho,'torig','down','color','m','linestyle',':');
Output argument "H" (and maybe others) not assigned during call to "D:\matlab\work\polarhg.m (polarhg)".
Error in ==> polarhg at 56
N = nargin;
-----------------------
解决问题:改第286⾏的num2str(Rmax-i)。
暂时没有下到polarhg.m⽂件。。。
——-----------------------------------------------------------------------------
个⼈推荐直接改polar.m⽂档,简单易实现。。。。
附:
修改后的Mypolar程序如下:
function hpol =
Mypolar(varargin)
%POLAR Polar
coordinate plot.
% POLAR(THETA, RHO) makes a plot using polar coordinates
of
% the angle THETA, in radians, versus the radius RHO.
% POLAR(THETA, RHO, S) uses the linestyle specified in string
S.
% See PLOT for a description of legal linestyles.
%
% POLAR(AX, ...) plots into AX instead of GCA.
%
% H = POLAR(...) returns a handle to the plotted object in
H.
%
% Example:
% t = 0 : .01 : 2 * pi;
% polar(t, sin(2 * t) .* cos(2 * t), '--r');
%
% See also PLOT, LOGLOG, SEMILOGX, SEMILOGY.
% Copyright 1984-2010 The MathWorks, Inc.
% $Revision: 5.22.4.11 $ $Date: 2011/03/09 06:59:01 $
% Parse possible Axes
input
[cax, args, nargs] = axescheck(varargin{:});
error(nargchk(1, 3, nargs, 'struct'));
if nargs < 1 || nargs
杭州现代汽修学校> 3
error('MATLAB:polar:InvalidInput',
'Requires 2 or 3 data
arguments.');
elseif
nargs ==
2
theta = args{1};
rho = args{2};
if ischar(rho)
line_style = rho;
廿四史rho = theta;
[mr, nr] = size(rho);
if
mr ==
1
theta = 1 : nr;
else
th = (1 : mr)';
theta = th(:, ones(1, nr));
end
else
line_style = 'auto';
end
elseif
nargs ==
1

本文发布于:2024-09-20 20:21:56,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/152061.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:修改   没有   命令   增加
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议