I'm using python and matplotlib to generate graphical output. I am creating multiple plots within a loop and would like the loop counter to serve as an index on the y-axis label. How do I get the loop counter (a variable) to appear as a subscript?
Here's what I have:
axis_ylabel = plt.ylabel(u"\u03b1 [\u00b0]", rotation='horizontal', position=(0.0,0.9))
resulting in:
α [°]
(I'm using unicode instead of Tex because dvipng is not available on this system.)
I would like something like this:
for i in range(1,3):
axis_ylabel = plt.ylabel(u"\u03b1" + str(i) + u" [\u00b0]", rotation='horizontal', position=(0.0,0.9))
No surprise, this gives:
α1 [°]
α2 [°]
What I really want is the numbers to be subscripts. How do I combine the conversion to a string with a command to create a subscript? Including a '_' is not recognized in the unicode environment to generate a subscript. Additionally, I still need python/matplotlib to recognize that this subscript-command should affect the following variable.
Any thoughts?
Edit
I got this far:
axis_ylabel = plt.ylabel(u"\u03b1" + r"$_" + str(i) + r"$" + u" [\u00b0]", rotation='horizontal', position=(0.0,0.9))
-- this results in a subscript character. However, it is NOT a conversion of the integer value but a different symbol.
Edit 2
I am using python 2.6.6 and matplotlib 0.99.1.1. Inserting any kind of string at <>
in r"$<>$"
will not result in the display of that string but an entirely different character. I have posted this issue as a new question.