简体   繁体   English

matplotlib轴中的下标

[英]Subscripts in matplotlib axes

I am trying to write some variable alpha with a subscript "mod" while putting text on one of my plots in matplotlib. 我在将文本放在matplotlib的其中一个绘图中时,尝试用下标“ mod”编写一些可变的alpha。 I know how to do one-letter or one-number subscripts via doing some along the lines of: 我知道如何通过以下方式来做一个字母或一个数字的下标:

r'$\alpha_i$'

which prints alpha with a subscript of "i", but is there anyway to code this so it can write multiple letters as subscripts instead of just one. 可以打印带有下标“ i”的字母,但是无论如何都可以对其进行编码,因此它可以写多个字母作为下标,而不仅仅是一个。 When I do 当我做

  r'$\alpha_mod$'

it print alpha with a subscript of "m" with od in normal letters 它以正常字母打印带有下标“ m”和od的alpha

Here is a quick example: 这是一个简单的示例:

import matplotlib.pyplot as plt
ax = plt.gca()
ax.text(2, 2, r'$\alpha_mod$', fontsize=10)
y = [2,3,4,5]
x = [1,2,3,4]
plt.plot(x,y)
plt.show()

Short answer: Use curly brackets $\\alpha_{mod}$ 简短答案:使用大括号$ \\ alpha_ {mod} $

Longer version: Matplotlib uses LaTeX format for strings. 较长的版本:Matplotlib对字符串使用LaTeX格式。 In LaTeX, if you want a subscript to include more than one letter you have to use curly brackets. 在LaTeX中,如果希望下标包含多个字母,则必须使用大括号。

import matplotlib.pyplot as plt
ax = plt.gca()
ax.text(2, 2, r'$\alpha_{mod}$', fontsize=10)
y = [2,3,4,5]
x = [1,2,3,4]
plt.plot(x,y)
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM