擅长:python、mysql、java
<p><a href="https://github.com/matplotlib/matplotlib/commit/852b41c1e59969e5e627b38fd392e926e13442ca" rel="nofollow noreferrer">Matplotlib does support tif since version 1.1</a>但是支持是可选的,并不明显。只要安装了<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow noreferrer">pillow</a>,就可以像保存为任何其他格式一样保存到tif。因此,你的例子很简单:</p>
<pre><code># -*- coding: utf-8 -*-
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import PIL # not necessary but mustn't fail
# 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')
</code></pre>