Matplotlib xlabel in Arial with one word italicised

Viewed 7720

I want to create a matplotlib figure with an x-axis label that is in Arial font, and has one word italicised.

I can create figures with x-axis labels in latex-font with one word italicised; I can also create figures with x-axis labels in Arial, as long as I have either the entire label italicised or the entire label normal; but I can't get part of the xlabel in Arial italicised and the other part in arial normal.

I'm mostly trying permutations of the following code:

from matplotlib import pyplot as plt
import numpy as n
import matplotlib
from matplotlib.font_manager import FontProperties
font = {'family' : 'Arial',
    'weight' : 'medium',
    'size'   : 20,
    'style'  : 'normal'}
font0 = {'family' : 'Arial',
    'weight' : 'medium',
    'size'   : 20,
    'style'  : 'italic'}


matplotlib.rcParams['mathtext.fontset'] = 'custom'
matplotlib.rcParams['mathtext.rm'] = 'Arial'
matplotlib.rcParams['mathtext.it'] = 'Arial'


matplotlib.rc('font', **font)
#matplotlib.rc('font', **font0)
matplotlib.rc('text', usetex=False)

plt.figure(); plt.plot(n.linspace(0,3,10), n.linspace(0,3,10))
plt.xlabel(r'$\mathit{italics}$ - rest normal')
1 Answers
Related