1

Referring to this question thread Matplotlib: Italic style in regular font, I'm not able to achieve the same results with the latest python version 3.9.13 (I can achieve this previously).

I want to label the x-axis as the displacement in Angstrom mathsymbol with the same Times New Roman font in italic style.

plt.rcParams['mathtext.fontset'] = 'stix'

plt.xlabel("Displacement ($\mathregular{\mathit{\AA}}$)",fontname="Times New Roman",fontsize=12)

I can obtain the Angstrom symbol in italic style, but not same Times New Roman fontstyle (Even though I have applied the mathtext fontset stix). If I try this:

plt.xlabel("Displacement ($\mathregular{\AA}$)",fontname="Times New Roman",fontsize=12)

I can obtain the Angstrom symbol in Times New Roman, but not in Italic style... What should I change to achieve this? Thanks

Picture of x-label:

Huhu
  • 11
  • 2

1 Answers1

1

Use \mathrm{\AA} with the STIXGeneral font family, which comes with Matplotlib. This will render the symbol in non-italic style; \AA will render it in italics. I included both in the following examples.

import matplotlib.pyplot as plt
plt.rcParams['mathtext.fontset'] = 'stix'
plt.xlabel(r'Displacement ($\mathrm{\AA}$) ($\AA$)', fontname='STIXGeneral', fontsize=12)
plt.show()

STIX label

Note that the ticks on the x-axis and y-axis still use the default font (DejaVu Sans). If you want to use Times New Roman for everything, just set the font.family parameter.

import matplotlib.pyplot as plt
plt.rcParams['mathtext.fontset'] = 'stix'
plt.rcParams['font.family'] = 'STIXGeneral'
plt.xlabel(r'Displacement ($\mathrm{\AA}$) ($\AA$)', fontsize=12)
plt.show()

STIX everywhere

Tested on Python 3.8.10 and 3.10.8.

tfpf
  • 612
  • 1
  • 9
  • 19
  • Hi Thanks for the reply! Unfortunately it didn't work. I have provide more detailed explanation in next section and appreciate if you have a look through. Thanks – Huhu Nov 25 '22 at 14:20