问题
How can I save a 3d pyplot image so that I can still rotate it in my pdf viewer? I know pdfs can be saved so that the 3d image can be rotated (I've had files like this before) - how can I accomplish this using pyplot? The motivation for this question is that I want to share images which others can rotate - it is not sufficient for me to rotate the image in the python viewer, taking 2d snapshots.
Here is my example code. I cannot rotate the image in the pdf which this generates.
import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.random.random(1000)
Y = np.random.random(1000)
Z = np.random.random(1000)
xi = np.linspace(X.min(),X.max(),100)
yi = np.linspace(Y.min(),Y.max(),100)
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')
ax = fig.add_subplot(111, projection='3d')
xig, yig = np.meshgrid(xi, yi)
surf = ax.plot_surface(xig, yig, zi,linewidth=0)
plt.savefig('/Users/kilojoules/Downloads/ex.pdf')
回答1:
3D PDF files have an internal structure called a 3D annotation that can contain a 3D model in the Universal 3D (U3D) or PRC format. If your PDF file has a 3D annotation, you can view/rotate/markup in 3D. There are a number of companies (such as www.dimensionpdf.com) that make tools for creating 3D PDF files from popular CAD packages (like AutoCAD).
If you cannot rotate the 3D model, then the PDF most likely contains just a 2D image of a 3D model, rather than a 3D annotation.
来源:https://stackoverflow.com/questions/32342276/pyplot-to-3d-pdf