user2685704
user2685704

Reputation: 21

Generating the 3d graph in python is easy, but I can't seem to figure out how to display the 3d graph on the pdf

Here is the code:

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

data = [[1.3, 125, 0.0152093 ],
        [1.3, -40, 0.00864026],
        [3.6, 125, 0.0226226 ],
        [3.6, -40, 0.0221346 ],
        [5.5, 125, 0.0400638 ],
        [5.5, -40, 0.0417146 ],
        [1.1, 125, 0.053118  ],
        [1.65, 125, 0.0631874 ],
        [2.3, 125, 0.0828577 ]]


x, y, z = zip(*data)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x,y,z)
ax.set_title("Process: FF")
ax.set_xlabel('Voltage')
ax.set_ylabel('Temperature')
ax.set_zlabel('Power value')

#ax.plot_wireframe(x, y, z, rstride=10, cstride=10)

plt.show()
plt.savefig('example01.pdf') 

Please help me to save the 3d graph in the pdf.

Upvotes: 1

Views: 2206

Answers (2)

M4rtini
M4rtini

Reputation: 13539

Switch the plt.show() and plt.savefig(...) line. plt.show() locks execution, and won't continue until you close the figure. And then when it tries to save the plot after you close it, it's already gone.

Alternatively you can try to save it through the plt.show dialog, then you can interactively rotate it to get the view you want.

plt.savefig('example01.pdf') 
plt.show()

Try calling plt.show() twice and see that nothing shows up the second time, to prove for yourself that this is the case.

Upvotes: 1

MattDMo
MattDMo

Reputation: 102842

From the savefig() docs,

plt.savefig('example01.pdf', format='pdf')

should work.

Upvotes: 1

Related Questions