17

プロットのフォント レイアウトを管理するために Latex を使用するために、matplotlib で usetext=True を設定しました。図に示すように、x 軸と xticklabel の間のスペースは、正の値と負の値で異なります。

同じスペースを取得する可能性はありますか?

例:

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(-10.0, 10.0, 100)
s = np.cos(t)

plt.rc('text', usetex=True)

plt.rc('font', family='serif', size=30)
plt.plot(t, s)

plt.show()

ここに画像の説明を入力

4

4 に答える 4

1

これは一種の「ハッキー」な方法であり、なぜそれが修正されるのかわかりませんが、FormatStrFormatterfromを使用matplotlib.tickerすると修正されるようです。唯一の違いは、フォントの太さが太字に見えることです。私はそれを変えることはできないようですが、あなたはそれを扱うことができるかもしれません。

import numpy as np
import matplotlib.ticker as mtick
import matplotlib.pyplot as plt

t = np.linspace(-10.0, 10.0, 100)
s = np.cos(t)

plt.rc('text', usetex=True)
plt.rc('font', family='serif', size=30)

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(t, s)

fmtx = '%.0f%%'
fmty = '%.1f%%'
xticks = mtick.FormatStrFormatter(fmtx)
yticks = mtick.FormatStrFormatter(fmty)
ax1.xaxis.set_major_formatter(xticks)
ax1.yaxis.set_major_formatter(yticks)
plt.show()

ここに画像の説明を入力

于 2017-01-01T01:42:53.080 に答える