Question

I have a plot where the y label has a superscript for the order of magnitude in it which I produce with the following line:

# plt is acquired from matplotlib.pyplot
# orderMagnitude is a variable taken from a different part of the code
plt.ylabel('${\mathrm{Intensity (10^'+str(int(orderMagnitude))+')}}$')

The {\mathrm{..}} part was added because without it the whole text would be italic (except for the actual numbers). The line that I have now seems to remove the white space between the y (of intensity) and the opening '(' however and seems to add some whitespace after the orderMagnitude (see picture).

enter image description here

Does anyoneone know why this occurs?

Was it helpful?

Solution

You don't need to put the whole line in math mode, that is part of where you are running into trouble. In particular, you are putting the whole equation inside \mathrm{}, instead of just {Intensity }. The following would probably be better, and you shouldn't get the extra whitespace at the end:

plt.ylabel('Intensity $(10^{' + str(int(orderMagnitude)) + '})$')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top