문제

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?

도움이 되었습니까?

해결책

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)) + '})$')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top