2017-12-18 3 views
1

아래 코드를 실행 한 후에는 축 눈금 표시자가 모두 서로 중첩됩니다. 현재 확대/축소가 plt.show()으로 표시되면 각 마커의 해상도가 여전히 양호 할 수 있습니다. 그러나 plt.savefig('fig.png')으로 저장 한 수치는 해상도가 손실됩니다. 이것도 최적화 할 수 있습니까?plt.savefig를 사용하여 충분한 눈금 표시를 올바르게 표시하는 방법은 무엇입니까?

enter image description here

from matplotlib.ticker import FuncFormatter 
from matplotlib.pyplot import show 
import matplotlib.pyplot as plt 
import numpy as np 

a=np.random.random((1000,1000)) 

# create scaled formatters/for Y with Atom prefix 
formatterY = FuncFormatter(lambda y, pos: 'Atom {0:g}'.format(y)) 
formatterX = FuncFormatter(lambda x, pos: '{0:g}'.format(x)) 

# apply formatters 
fig, ax = plt.subplots() 
ax.yaxis.set_major_formatter(formatterY) 
ax.xaxis.set_major_formatter(formatterX) 

plt.imshow(a, cmap='Reds', interpolation='nearest') 

# create labels 
plt.xlabel('nanometer') 
plt.ylabel('measure') 
plt.xticks(list(range(0, 1001,10))) 
plt.yticks(list(range(0, 1001,10))) 

plt.savefig('fig.png',bbox_inches='tight') 
plt.show() 
+1

무화과 크기를 설정하는 데 도움이됩니까? – Cleb

+0

확대 된 이미지를 저장하는 방법을 묻는 중입니까? – ImportanceOfBeingErnest

답변

2

난 당신이, 예를 들어, 그림의 크기를 설정하여 그것을 해결할 수 있다고 생각

코멘트에 @PatrickArtner에 의해 지적
fig, ax = plt.subplots() 
fig.set_size_inches(15., 15.) 

, 당신은 또한

plt.xticks(list(range(0, 1001, 10)), rotation=90) 

대신

plt.xticks(list(range(0, 1001,10))) 

코드의 나머지 부분에 의해 X-진드기의 중복을 방지 할 수 있습니다 완전히 변함이 없다. 그 결과 출력은 적당 해 보입니다 (그러나 여기에 올리기에는 너무 큽니다).

+1

을 사용하면 x 축에 덮어 쓰기를 줄이기 위해 'plt.xticks (list (range (0, 1001,10)), rotation = 90) 레이블을 사용하면 많은 도움이됩니다. - 그 작은 비트에 대한 답변을하지 않을 수도 있습니다 :) 아마도 당신의 그것을 추가 할 수 있습니까? –

+0

@PatrickArtner : 고마워, 나는 그것을 추가했다. – Cleb

관련 문제