我正在使用Ezpolar函数来绘制一些图形。 其中三个最大值为4,但最后一个只有两个以上。
当我绘制它们时,最后一个绘制它的功能(看起来如果ezpolar在将ezpolar值用作半径后绘制一些像素)。
代码和生成的图
% This subplot is used since I've 4 graphics to draw. subplot(2,2,4) ezpolar('0.25*(5 - 4*cosd(-180 * sin(t) ))'); title('D')Code and Generated Plot
% This subplot is used since I've 4 graphics to draw. subplot(2,2,4) ezpolar('0.25*(5 - 4*cosd(-180 * sin(t) ))'); title('D')If I don't use this subplot, using a complete figure to draw the graphics seems fine. However, since I need to have all four of them together, it results in (will draw only the problematic one, subplot 2,2,4):
As you can see, r = 0.25 (5 - 4...) is plotted just over the polar axes.
Why is it happening? How can I fix it?
最满意答案
问题似乎在于该注释的位置以及当您使用subplot ,极坐标图的半径上的限制实际上会发生变化,但注释的位置却没有 。
为了解决这个问题,您实际上可以计算轴的极限并将文本的位置更改为明确地在绘图之外。
hax = subplot(2,2,4); p = ezpolar('0.25*(5 - 4*cosd(-180 * sin(t) ))'); % Get the handle to the label text object label = findobj(hax, 'type', 'text'); % Figure out the current axes limits ylims = get(hax, 'ylim'); % Add some padding (as a percent) to the position padding = 0.2; set(label, 'Position', [0 ylims(1)*(1 + padding), 0]);
更好的方法是将标签的Units更改为使用Normalized单位(相对于轴)而不是Data单位。 这样,如果轴限制发生变化,它就不会改变。
hax = subplot(2,2,4); p = ezpolar('0.25*(5 - 4*cosd(-180 * sin(t) ))'); % Get the handle to the label text object label = findobj(hax, 'type', 'text'); set(label, 'Units', 'Normalized', 'Position', [0.5, -0.2]);The issue appears to be with the position of that annotation and the fact that when you use a subplot, the limits on the radius of the polar plot actually change but the position of the annotation does not.
To combat this, you could actually compute the limits of the axes and change the position of the text to be explicitly outside of the plot.
hax = subplot(2,2,4); p = ezpolar('0.25*(5 - 4*cosd(-180 * sin(t) ))'); % Get the handle to the label text object label = findobj(hax, 'type', 'text'); % Figure out the current axes limits ylims = get(hax, 'ylim'); % Add some padding (as a percent) to the position padding = 0.2; set(label, 'Position', [0 ylims(1)*(1 + padding), 0]);A better way to do this would be to change the Units of the label to use Normalized units (relative to the axes) rather than Data units. This way, it will not change if the axes limits change.
hax = subplot(2,2,4); p = ezpolar('0.25*(5 - 4*cosd(-180 * sin(t) ))'); % Get the handle to the label text object label = findobj(hax, 'type', 'text'); set(label, 'Units', 'Normalized', 'Position', [0.5, -0.2]);更多推荐
发布评论