I have a polar plot. Is there a way to label the axes?

For the r axis, I would like to label "Energy (eV)" How do I do that?

1 Comment

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.

Sign in to comment.

 Accepted Answer

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 Comments

Interesting!
This was not obvious! I looked in the polar axes properties documentation expecting to see something there, but you would have to already know about RAxis and numeric rulers. It does not seem to make sense that there is explicit description of things like the RTickLabel when those would logically be part of the appropriate ruler, but no mention of the overall label property unless you think to look under the hood.
I didn’t see it when I looked at the documentation for polaraxes. That’s the reason I suggested the approach in my Answer.
Perhaps we should mention this to Yair Altman for inclusion in ‘Undocumented MATLAB’?
------------------------------------
Why do I even bother? I think I’ll go play SKYRIM. It’s more fun than playing ‘Guess What I’m Thinking’ with MathWorks documentation.
When I copy paste your answer into my chart, nothing appears. Am I missing something?
That option may not actually exist.
Walter:
The ruler objects are relatively new (introduced after the new graphics system, in release R2015b for numeric ruler and R2016b for datetime and duration rulers) and so the documentation may not have incorporated them into the property pages as seamlessly as it could.
Star Strider:
It wouldn't hurt to add a more advanced example that demonstrates the use of the ruler objects to the polaraxes and/or polarplot documentation pages. I can report that to the documentation staff tomorrow, but if you want to give that request more weight you can click on the "No" button for the "Was this topic helpful?" question in the lower-right corner of the page and make the same request. I know for a fact the documentation staff reads and considers this feedback.
The documentation is usually pretty good, but it's not perfect. If you see a place like this where there's room for Continuous Improvement, please let us know.
Benjamin:
Which release are you using? As I said in my answer, this should work in release R2016a or later. If you're using that release or later, and it's not showing up, please show a SMALL segment of code.
I have something like this below. All I want to do is label the r-axis with Energy (eV).
figure(3)
polarplot(a,f,'-ob')
hold on
polarplot(a,g,'-or')
hold on
polarplot(aa,ff,'-ok')
hold on
polarplot(aa,gg,'-og')
set(gca,'LineWidth',line_width)
rlim([0 r_scale])
title('YZ Plane')
thetaticks([0 15 30 45 60 75 90 105 120 135 150 165 180 195 210 225 240 255 270 285 300 315 330 345])
ax = gca;
ax.ThetaAxis.TickLabelInterpreter = 'latex';
ax.ThetaTickLabel = {'[010]','','','[011]','','','[001]','','','[0$\overline{1}$1]','','','[0$\overline{1}$0]','','','[0$\overline{1} \overline{1}$]','','','[00$\overline{1}$]','','','[01$\overline{1}$]','','','[0$\overline{1}$ $\overline{1}$]'};
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.

Sign in to comment.

More Answers (2)

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.
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 Comments

I guess I am confused - you mean there is not a way to label my axis?
Apparently there is, since Steven Lord says so. It’s just not in the documentation, so I didn’t know it existed. The 'RTickLabel' option is as close as I could come. It labels the radius ticks, using the sort of cell array I created in ‘eVlbl’.
I’ll delete my Answer in a few hours, since it’s obviously not contributing anything substantive.
Whenever I use the code that he wrote, my entire plot messes up. I attached my code above.
Is that enough to reproduce your plot? Do you need to attach your data also? What version of MATLAB are your running?
The version is MATLAB 2016b. I assumed my data was irrelevant. Just add any number to those and it should plot something.
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?
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.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!