如何在matplotlib中为对数图中的科学数字设置字体?

2024-04-26 02:52:15 发布

您现在位置:Python中文网/ 问答频道 /正文

通过rcParams设置字体时,例如

import matplotlib as mpl

mpl.rcParams['font.sans-serif'] = ['FreeSans', ]

对数图的字体不变。而是保留默认字体类型。你知道吗

import matplotlib.pyplot as plt
from numpy import arange
plt.ion()
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
for n in range(1, 10):
    ax1.plot(range(1, 10), arange(1, 10)**n, label='poly{}'.format(n))
    ax2.plot(range(1, 10), arange(1, 10)**n, label='poly{}'.format(n))
ax1.set_xscale('log')
ax1.set_yscale('log')
ax2.legend(ncol=2);

lin-and-log-plot

我想知道有没有办法设置科学的字体类型?你知道吗

(勾选两个图中的“一”可以看到不同的字体。)


Tags: importadd类型matplotlibasfig字体range

热门问题