Save 3d plot as vector format

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

Is there a way to export a 3d plot as a pdf file?

I know you can't do p.save('filename.extension') because 3dplot doesn't create a graphics item. But is there a way to do this?

asked Jun 10 '12

daniel.e2718 gravatar image daniel.e2718
41 1 9

3 Answers:

i like this answer (click again to cancel)
4
i dont like this answer (click again to cancel) daniel.e2718 has selected this answer as correct

The Sage 3D plots don't support output in a 2D vector format (like PDF), at least not for now. You can do it by calling matplotlib directly: PDF version of the image below

image description

from mpl_toolkits.mplot3d import axes3d
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rc
rc('text', usetex=True)

rays = [(-3, -2, 4), (0, 1, 0), (1, 0, 0), (2, 1, -4)]
extrapoints = [(-1, -1, 2), (1, 1, -2)]
cones = [[0,1,2],[0,1,3],[0,2,3],[1,2,3]]

poly3d = []
for cone in cones:
    verts = [ rays[i] for i in cone ]
    poly3d.append(verts)

polygons = Poly3DCollection(poly3d, facecolor='green', 
                            linewidths=2,
                            alpha=0.1)
polygons.set_alpha(0.3)

fig = plt.figure()
fig.set_figwidth(13.0/2.54)
fig.set_figheight(9.0/2.54)

ax = axes3d.Axes3D(fig)
ax.scatter3D(*zip(*rays), s=50, c='red')
ax.scatter3D(*zip(*extrapoints), s=50, c='blue')
ax.scatter3D([0],[0],[0], s=20, c='black')

ax.add_collection3d(polygons)  
ax.set_xlabel(r'$X$')
ax.set_ylabel(r'$Y$')
ax.set_zlabel(r'$Z$')
ax.set_xlim3d(-3, 2)
ax.set_ylim3d(-2, 1)
ax.set_zlim3d(-4, 4)

r = rays[0]
ax.text(r[0]-0.2,r[1],r[2], r'${}^{'+str(r)+'}$', 
        horizontalalignment='right',
        verticalalignment='top',
        color='red')

r = rays[3]
ax.text(r[0]-0.2,r[1],r[2], r'${}^{'+str(r)+'}$', 
        horizontalalignment='right',
        verticalalignment='top',
        color='red')

r = rays[1]
ax.text(r[0],r[1],r[2]+0.3, r'${}^{'+str(r)+'}$', 
        horizontalalignment='center',
        verticalalignment='bottom',
        color='red')

r = rays[2]
ax.text(r[0],r[1],r[2]-0.3, r'${}^{'+str(r)+'}$', 
        horizontalalignment='center',
        verticalalignment='top',
        color='red')

r = extrapoints[0]
ax.text(r[0],r[1],r[2]-0.3, r'${}^{'+str(r)+'}$', 
        horizontalalignment='center',
        verticalalignment='top',
        color='blue')

r = extrapoints[1]
ax.text(r[0]+0.2,r[1],r[2], r'${}^{'+str(r)+'}$', 
        horizontalalignment='left',
        verticalalignment='bottom',
        color='blue')


ax.text(-0.2,0,0, r'${}^0$', 
        horizontalalignment='right',
        verticalalignment='top',
        color='black')

# plt.show()

for axis in [ax.w_xaxis, ax.w_yaxis, ax.w_zaxis]:
    axis.get_major_locator()._integer = True
    for t in axis.get_ticklabels(): 
        t.set_fontsize(6)

plt.savefig('fig_NablaBsing.pdf', bbox_inches='tight')
link

posted Jun 11 '12

Volker Braun gravatar image Volker Braun
2238 5 22 52

That response made me think curse words. Seems like a lot of work for one picture.

daniel.e2718 (Jun 20 '12)
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

I don't think the 3d plots support output to a PDF. I have gotten a TIFF, however, and then converted it to a PDF.

You can also use the viewer='tachyon' option and get a TIFF (but not a PDF).

link

posted Jun 10 '12

calc314 gravatar image calc314
1820 3 19 51
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Another option that might work is a screen capture to a PDF, although it's not an elegant solution. This has the advantage of letting you turn the 3D graphic to the viewpoint that you'd like and then getting the image. To do that otherwise requires some dancing using Tachyon commands, as I understand it.

link

posted Jun 11 '12

calc314 gravatar image calc314
1820 3 19 51

updated Jun 11 '12

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Jun 10 '12

Seen: 335 times

Last updated: Jun 11 '12

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.