線幅に敏感なかなり繊細なフィーチャがいくつかあります。この図を簡単に印刷できるPDFとして保存します(つまり、受信者の側でスケーリングを行わず、Command + Pを押して移動します)。残念ながら、印刷用にPDFのサイズを正しく設定するためにfigsize =(8.5,11)を設定すると、matplotlibは非常に太いデフォルトの線幅とテキストサイズを選択してプロットを乱してしまいます(凡例は大きすぎます)オーバーラップ)。私がfigsize =(17,22)を設定した場合、印刷のためにPDFを50%にスケーリングした後、非常に実行可能なデフォルトの線幅とテキストサイズが得られます。これは私が使ってきたことですが、その解決策は政治のために役に立たなくなってしまい、変更を行うたびにPDFをイラストレーターに拡大したくありません。matplotlib PDFを保存するときの線幅
ビットマップを使用することができたら、dpiパラメータを無視しているように見えるので、figsize =(17,22)に設定してdpiを目標dpiの半分に設定することで希望の結果を得ることができました。 。私は
- が
- を編集することができboxes_good.png(細い線でサイズだまさビットマップ、小さなテキスト)(それがないようにまたは印刷物)
- が8.5x11in寸法を持っているように見えるPDFを希望しますイラストレーターのビットマップではありません。
PDFとして保存するときに「ダブルサイズ、ハーフdpi」のトリックを簡単に取り込む方法があるとは思いますが、それを働かせることをあきらめ、線幅とテキストサイズを直接操作しようとしました。 textsizeは変更できましたが、線幅は変更できませんでした。ここに私が試した事の記録は次のとおりです。ここで
# Tried:
# fig.set_size_inches(17,22)
# fig.savefig('boxes.pdf', dpi=100,150,300)
# dpi parameter has no effect on linewidth, text size, or the PDF's dimensions
# 'markerscale=.5' on plt.legend and pax.legend
# no effect
# mp.rcParams['font.size']=8
# worked! made text smaller, now for linewidth...
# mp.rcParams['lines.linewidth']=5
# no effect
# fig.set_linewidth(5)
# no effect
# pax.axhline(linewidth=5)
# only changes x axis not box surrounding subplot
# fig.set_size_inches(8.5,11) immediately before plt.savefig('boxes.pdf')
# identical results to calling plt.figure(figsize=(8.5,11)) in the first place
# I tried passing plt.figure(figsize=(17,22)) and swapping it to 8.5x11 using
# fig.set_size_inches right before saving, but the lines were thick and the text
# was large in the PDF, exactly as if I had set figsize=(8.5,11) to begin with
はsourcefileのです(私は必需品へのプロットが低下しているので、明白なスタイリングの回避策は、おそらく実行可能なソリューションではありません)
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
x = np.arange(200)
bottom_red_bar = -np.random.random(200)
bottom_black_bar = np.random.random(200) * bottom_red_bar
fig = plt.figure()
for subplotnum in [1,2,3]:
pax = plt.subplot(310+subplotnum)
pax.set_ylim([-1,1])
bot_rb = pax.bar(x, bottom_red_bar,1,color='r')
bot_bb = pax.bar(x+(1-.3)/2,bottom_black_bar,.3,color='k')
pax.legend([bot_rb,bot_bb],['Filler Text 1','Filler Text 2'],loc=4)
fig.set_size_inches(8.5,11)
fig.savefig('boxes_bad.png',dpi=300) # Lines are too thick
fig.set_size_inches(17,22)
fig.savefig('boxes_good.png',dpi=150) # Lines are just right
fig.set_size_inches(8.5,11)
plt.savefig('boxes.pdf') # Lines are too thick
fig.set_size_inches(17,22) # Lines are just right
plt.savefig('boxes.pdf') # but the PDF needs scaling before printing
だから私は、図全体の線幅を調整する方法や、matplotlibにfigsizeとは異なる次元メタデータを含むpdfを保存させる方法をとっています。助言がありますか?