2016-07-22 2 views
0

다음은 예제입니다. 다음은 .PNG로 저장된 무엇을 얻을이는 화면에 표시하는 방법이며Matplotlib은 화면에 표시되는 것과 다른 .svg를 저장합니다.

this is the image that looks right

정확하고 다음은 히트 맵

에 대한 보간을 사용하는 .svg입니다 enter image description here

그들은 모두 각각

plt.savefig(filename,format='png') 
plt.savefig(filename,format='svg') 

그리고 t을 코드의 다음 줄을 사용하여 저장됩니다 그는 다음에 실제 플롯을 생성하는 코드입니다.

def heatmapText(data,xlabels=[],ylabels=[],cmap='jet',fontsize=7): 
    ''' 
    Heatmap with text on each of the cells 
    ''' 


    plt.imshow(data,interpolation='none',cmap=cmap) 

    for y in range(data.shape[0]): 
     for x in range(data.shape[1]): 
      plt.text(x , y , '%.1f' % data[y, x], 
        horizontalalignment='center', 
        verticalalignment='center', 
        fontsize=fontsize 
        ) 

    plt.gca() 
    if ylabels!=[]: 
     plt.yticks(range(ylabels.size),ylabels.tolist(),rotation='horizontal') 
    if xlabels!=[]: 
     plt.xticks(range(xlabels.size),xlabels.tolist(),rotation='vertical') 

두 플롯의 경우 정확히 동일한 기능을 사용했지만 다른 형식으로 저장했습니다. 마지막으로 .png와 같이 화면이 올바르게 표시됩니다.

.svg를 사용하여 파일을 올바르게 저장하는 방법에 대한 아이디어가 있으십니까?

답변

1

http://matplotlib.org/examples/images_contours_and_fields/interpolation_none_vs_nearest.html

What does matplotlib `imshow(interpolation='nearest')` do?

matplotlib shows different figure than saves from the show() window

내가 interpolation=nearest

다음 코드로 이것을 시도하는 것이 좋습니다거야 바탕으로 표시로 저장 나에게 동일한 제공 svg 음모 :

import matplotlib.pyplot as plt 
import numpy as np 

A = np.random.rand(5, 5) 
plt.figure(1) 
plt.imshow(A, interpolation='nearest') 

plt.savefig('fig',format='svg') 
plt.show() 
+0

매력처럼 작동합니다! 감사합니다. – Juli

관련 문제