Printing subscript in python

后端 未结 5 570
逝去的感伤
逝去的感伤 2020-12-03 01:53

In Python 3.3, is there any way to make a part of text in a string subscript when printed?

e.g. H₂ (H and then a subscript 2)

5条回答
  •  一个人的身影
    2020-12-03 02:43

    If you want to use it on the axes of a plot you can do:

    import matplotlib.pyplot as plt
    plt.plot([1])
    plt.ylabel(r'$H_{2}$')
    plt.show()
    

    which gives

提交回复
热议问题