TeX compiles $A_{\textrm{C-C}}$
displaying a hyphen in the subscript. How can I produce the same result in matplotlib without using TeX? The command \textrm
is from the amstext package and produces an unknown symbol error in the default math text.
I tried the following code (resulting in an unknown symbol error):
#!/usr/bin/env python
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.axis([0, 2, 0, 2])
ax.text(1, 1, r'$A_{\textrm{C-C}}$')
plt.show()
CodePudding user response:
Try this:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.axis([0, 2, 0, 2])
ax.text(1, 1, r'$A_{C-C}$')
plt.show()
Hope it helps
from here
CodePudding user response:
Inserting a Unicode hyphen (u"\u2010"
) produced the correct text:
#!/usr/bin/env python
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.axis([0, 2, 0, 2])
ax.text(
0.1, 1.2, r'$A_\mathrm{C' u"\u002D" r'C}$'
' unicode hyphen-minus U 002D')
ax.text(
0.1, 1.0, r'$A_\mathrm{C-C}$'
' ASCII hyphen')
ax.text(
0.1, 0.8, r'$A_\mathrm{C' u"\u2010" r'C}$'
' unicode hyphen U 2010 produces a result similar to textrm')
plt.show()