I have a polar plot. Is there a way to label the axes?
154 次查看(过去 30 天)
显示 更早的评论
For the r axis, I would like to label "Energy (eV)" How do I do that?
1 个评论
Walter Roberson
2017-1-9
编辑:Walter Roberson
2017-1-9
Oddly, the new polarplot() that creates Polar Axes objects, has no provision for axes labels.
I just now put in an enhancement request for this.
采纳的回答
Steven Lord
2017-1-9
In release R2016a or later if you create a polaraxes, either using that function directly or by creating a polarplot, you can get the RAxis property of that polaraxes. The RAxis object has a property named Label that contains a text object, and that text object has a property named String.
ax = polaraxes;
rule = ax.RAxis;
rlabel = rule.Label;
rlabel.String = 'hello world';
You can chain together the property references if you want to make this a two line code:
ax = polaraxes;
ax.RAxis.Label.String = 'dlrow olleh';
7 个评论
Steven Lord
2017-1-11
Try running this. I had to generate some simple a and f data, but it should show the general technique.
a = sort(pi*rand(1, 100));
f = sin(a);
polarplot(a, f, '-ob')
ax = gca;
rruler = ax.RAxis;
rruler.Label.String = 'Energy (eV)';
The rruler.Label object has properties Interpreter and Rotation, among others, so you can customize it even more than simply changing the String.
更多回答(2 个)
Walter Roberson
2017-1-9
polar() is pretty much plot() of pol2cart() behind the scenes. There is no support for r or theta labels. There is the xlabel and ylabel from the underlying axes, but that is not very useful.
So, what you have to do is pick out an axes position in r and theta terms, pol2cart those into x y components, and text() at that position.
0 个评论
Star Strider
2017-1-9
If you have R2016a or later, use the polarplot function. It gives you the option of specifying the 'RTickLabel' (link) values. That is likely as close as you can get to what you want to do.
You will need to use sprintf and strsplit to create the labels and a cell array to use as the radius labels.
Example:
eV = linspace(0, 10, 5);
eVstr = sprintf('%.1f eV\n', eV);
eVlbl = strsplit(eVstr, '\n');
eVlbl = eVlbl(1:end-1);
The last element of the original ‘eVlbl’ is an empty string that can cause problems with vector length matching, so it is necessary to eliminate it by the second ‘eVlbl’ assignment.
Experiment with it. If you have problems, describe them here. We can help.
7 个评论
Star Strider
2017-1-11
I was specifically suggesting the arguments to your polarplot calls. Do we need those to understand your problem, or will any vectors do for ‘a’, ‘f’ and the rest?
Walter Roberson
2017-1-12
The example Steven http://www.mathworks.com/matlabcentral/answers/319725-i-have-a-polar-plot-is-there-a-way-to-label-the-axes#comment_419725 gave works for me. I would not say that the location or direction it chooses is exactly my first choice. You might want to set the ruler Rotation to 0 or change the font size or something like that.
另请参阅
类别
在 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!