2

OSX 10.8.3でPython 2.7でMatplotlib 1.2.0を使用していますが、次のようなプロットがあります:

ここに画像の説明を入力

ご覧のとおり、右側の凡例テキストが凡例ボックスに完全に収まらないという問題があります。凡例テキストのフォント サイズを変更しても役に立ちません。一方、問題は PDF バックエンドにあることがわかりました。たとえば、プロットを JPEG として保存すると、テキストはボックスに完全に収まります。

関連するコード部分は次のとおりです。

import matplotlib.pyplot as plt

plt.figure(0, figsize=(10, 6))
ax = plt.subplot(111)
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])

ax.plot(
    x, y,
    # I construct the labels dynamically like this 
    label=str(pr_auc_values[result_id])  + '  |  ' + filenames[result_id]
)

box = ax.get_position()
ax.set_position([box.x0, box.y0 + box.height * 0.15, box.width, box.height * 0.85])
plt.legend(loc='upper center', title='AUC Scores', fontsize=7, bbox_to_anchor=(0.5, -0.1))

# Saving as PDF leads to overfitting text
# Saving as JPEG works fine, though
plt.savefig('my_beautiful_plot.pdf')

凡例ボックスがテキストの長さに適応するには、どの設定を構成する必要がありますか?

4

0 に答える 0