当前位置:   article > 正文

python 上标,Python图中的上标

python r的平方怎么写成上标

I want to label my x axis at follows :

pylab.xlabel('metres 10^1')

But I don't want to have the ^ symbol included .

pylab.xlabel('metres 10$^{one}$')

This method works and will superscript letters but doesn't seem to work for numbers .

If I try :

pylab.xlabel('metres 10$^1$')

It superscripts a letter N for some reason .

Anyone know how to superscript numbers in python plots ?

thanks .

解决方案

You just need to have the full expression inside the $. Basically, you need "meters $10^1$". You don't need usetex=True to do this (or most any mathematical formula).

You may also want to use a raw string (e.g. r"\t", vs "\t") to avoid problems with things like \n, \a, \b, \t, \f, etc.

For example:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.set(title=r'This is an expression $e^{\sin(\omega\phi)}$',

xlabel='meters $10^1$', ylabel=r'Hertz $(\frac{1}{s})$')

plt.show()

nq03a.png

If you don't want the superscripted text to be in a different font than the rest of the text, use \mathregular (or equivalently \mathdefault). Some symbols won't be available, but most will. This is especially useful for simple superscripts like yours, where you want the expression to blend in with the rest of the text.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.set(title=r'This is an expression $\mathregular{e^{\sin(\omega\phi)}}$',

xlabel='meters $\mathregular{10^1}$',

ylabel=r'Hertz $\mathregular{(\frac{1}{s})}$')

plt.show()

ID8IJ.png

For more information (and a general overview of matplotlib's "mathtext"), see: http://matplotlib.org/users/mathtext.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/172209
推荐阅读
相关标签
  

闽ICP备14008679号