필자는 선폭에 민감한 상당히 섬세한 특징이있는 그림이 있습니다. 이 수치를 쉽게 인쇄 할 수있는 PDF로 저장하고 싶습니다 (즉, 수신자 측에서 크기 조정을하지 않고 Command + P 만 누르고 이동). 불행히도 인쇄용으로 PDF의 크기를 올바르게 지정하기 위해 figsize = (8.5,11)를 설정하면 matplotlib는 매우 두꺼운 기본 선 폭과 텍스트 크기를 선택하여 플롯을 엉망으로 만듭니다 (범례가 너무 커서 막대 그래프의 선이 나타납니다). 오버랩). 만약 figsize = (17,22)로 설정하면 인쇄를 위해 PDF를 50 %로 스케일링 한 후에 매우 유용한 기본 선 두께와 텍스트 크기를 얻습니다. 이것은 내가 사용해온 것이지만 정치로 인해 그 해결책이 실현 불가능 해졌으며 변경을 할 때마다 일러스트 레이터에서 PDF의 크기를 조정하고 싶지 않습니다.PDF를 저장할 때 matplotlib 선 두께
비트 맵을 사용하여 작업 할 수 있다면 dspi 매개 변수가 무시되는 것처럼 보이기 때문에 figsize = (17,22)로 설정하고 dpi를 대상 dpi의 절반으로 설정하여 원하는 결과를 얻을 수 있지만 PDF에서는 작동하지 않습니다. . 나는
- 는
- 편집 할 수 boxes_good.png (얇은 선으로 크기 - 속임수 비트 맵, 작은 텍스트()가하는 것처럼 또는 인쇄)
- 이 8.5x11in 차원이처럼 보이는 PDF 싶습니다 (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를 저장하는 방법을 사용한 후. 어떤 제안?