2016-06-21 3 views
4

matplotlib 그림을 * .tiff로 저장하는 방법을 아는 사람이 있습니까? 파이썬에서는이 형식이 지원되지 않는 것 같지만, 저널은 종종 그 형식을 요구합니다.Python matplotlib를 TIFF로 저장

fig.savefig('3dPlot.pdf') 

을하지만 그렇지 않은 :

# -*- coding: utf-8 -*- 

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 

# fig setup 
fig = plt.figure(figsize=(5,5), dpi=300) 
ax = fig.gca(projection='3d') 
ax.set_xlim([-1,1]) 
ax.set_ylim([-1,1]) 
ax.set_zlim([-1,1]) 
ax.axes.xaxis.set_ticklabels([]) 
ax.axes.yaxis.set_ticklabels([]) 
ax.axes.zaxis.set_ticklabels([]) 

# draw a surface 
xx, yy = np.meshgrid(range(-1,2), range(-1,2)) 
zz = np.zeros(shape=(3,3)) 
ax.plot_surface(xx, yy, zz, color='#c8c8c8', alpha=0.3) 
ax.plot_surface(xx, zz, yy, color='#b6b6ff', alpha=0.2) 

# draw a point 
ax.scatter([0],[0],[0], color='b', s=200) 

이 작동 : 해결 방법으로

fig.savefig('3dPlot.tif') 
+0

(cStringIO 모듈을 사용할 수없는 때문에 나는 오히려 BytesIO을 사용)? 나는 티파니가 사진이나 어쩌면 예술적 이미지에만 사용될 것이라고 생각했습니다. – syntonym

+0

[원본 데이터를 tif로 저장] (0120-385-2112) – Deadpool

+0

불행하게도 tiff-s를 요청합니다. 나는 그것이 이상하다는 것을 안다. 또한 나는 그걸로 일하지 않았다. – striatum

답변

2

대단합니다! 고마워요 Martin Evans. 이 Python3.x에서 일어날 수 있도록하고자하는 사람들을위한 그러나 , 작은 수정, 저널 정말 생성 된 사진의 tiffs가 필요하십니까

# -*- coding: utf-8 -*- 

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 

from PIL import Image 
from io import BytesIO 

# fig setup 
fig = plt.figure(figsize=(5,5), dpi=300) 
ax = fig.gca(projection='3d') 
ax.set_xlim([-1,1]) 
ax.set_ylim([-1,1]) 
ax.set_zlim([-1,1]) 
ax.axes.xaxis.set_ticklabels([]) 
ax.axes.yaxis.set_ticklabels([]) 
ax.axes.zaxis.set_ticklabels([]) 

# draw a point 
ax.scatter([0],[0],[0], color='b', s=200) 

# save figure 
# (1) save the image in memory in PNG format 
png1 = BytesIO() 
fig.savefig(png1, format='png') 

# (2) load this image into PIL 
png2 = Image.open(png1) 

# (3) save as TIFF 
png2.save('3dPlot.tiff') 
png1.close() 
5

중지 아무것도 없을 것이다

나는 최소한의 코드를 추가하고 파이썬 PIL 패키지를 사용하여 이미지를 TIFF 형식으로 저장하십시오 :

# -*- coding: utf-8 -*- 

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 

from PIL import Image 
import cStringIO 


# fig setup 
fig = plt.figure(figsize=(5,5), dpi=300) 
ax = fig.gca(projection='3d') 
ax.set_xlim([-1,1]) 
ax.set_ylim([-1,1]) 
ax.set_zlim([-1,1]) 
ax.axes.xaxis.set_ticklabels([]) 
ax.axes.yaxis.set_ticklabels([]) 
ax.axes.zaxis.set_ticklabels([]) 

# draw a surface 
xx, yy = np.meshgrid(range(-1,2), range(-1,2)) 
zz = np.zeros(shape=(3,3)) 
ax.plot_surface(xx, yy, zz, color='#c8c8c8', alpha=0.3) 
ax.plot_surface(xx, zz, yy, color='#b6b6ff', alpha=0.2) 

# draw a point 
ax.scatter([0],[0],[0], color='b', s=200) 

#fig.savefig('3dPlot.pdf') 

# Save the image in memory in PNG format 
png1 = cStringIO.StringIO() 
fig.savefig(png1, format="png") 

# Load this image into PIL 
png2 = Image.open(png1) 

# Save as TIFF 
png2.save("3dPlot.tiff") 
png1.close() 
관련 문제