Python Matplotlib Axis Label Subscript Based On Loop Counter
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.
Solution 1:
Matplotlib ships its own mathematical expression engine, called mathtext
.
From the documentation:
Note that you do not need to have TeX installed, since matplotlib ships its own TeX expression parser, layout engine and fonts.
So maybe try to use the following:
for i inrange(1,3):
plt.ylabel(
r"$\alpha_{:d} [\degree]$".format(i),
rotation='horizontal',
position=(0.0,0.9))
You can also use Unicode in mathtext
:
If a particular symbol does not have a name (as is true of many of the more obscure symbols in the STIX fonts), Unicode characters can also be used:
ur'$\u23ce$'
Post a Comment for "Python Matplotlib Axis Label Subscript Based On Loop Counter"