# point3d label axes

Hi,

I am completely new to sage (like only a few hours) and I am trying to create a labeled plot of the results from a PCA analysis.

here is what I am doing in the sage command line:

from matplotlib.mlab import PCA
pca_info=PCA(data)
a=point3d(pca_info.Wt[:3,])
a.show()


The problem is, I need to add labels to the axes to try and understand what the plot is giving. After googling a bit, I found people referring to

axes_labels(['x','y','z'])


But I when trying the following, I get an attribute error

a.axes_labels(['PCA1 (%0.3f)' %pca_info.fracs,
'PCA2 (%0.3f)' %pca_info.fracs,
'PCA3 (%0.3f)' %pca_info.fracs])


How does one generally add labels to a 3d plot, specifically to point3d()? Or has my googling failed me, and the answer is so obvious that I completely missed it.

edit retag close merge delete

Yeah, 3d plots and certain labels are not as far along as we'd like. It is possible (http://www.sagemath.org/doc/reference/sage/plot/plot3d/shapes2.html) to use text3d if you are lucky with positioning, perhaps?

Thanks for the info, it seems I have to use sage with something else, maybe something like mayavi.

Sort by » oldest newest most voted

Apart from not being able to fine-tune the axes, Sage's 3d plots don't support pdf output at this point.

You can use matplotlib (which is part of Sage) to create pseudo-3d plots with pdf output. Here is an example of how to do a 3d point plot with matplotlib and fiddle with the axes:

sage: points = [(-3, -2, 4), (0, 1, 0), (1, 0, 0), (2, 1, -4)]
sage: from mpl_toolkits.mplot3d import axes3d
sage: import matplotlib.pyplot as plt
sage: from matplotlib import rc
sage: rc('text', usetex=True)
sage: fig = plt.figure()
sage: fig.set_figwidth(13.0/2.54)
sage: fig.set_figheight(9.0/2.54)
sage: ax = axes3d.Axes3D(fig)
sage: ax.scatter3D(*zip(*points), s=50, c='red')
<mpl_toolkits.mplot3d.art3d.Patch3DCollection object at 0x6386750>
sage: ax.set_xlabel(r'$X$')
<matplotlib.text.Text object at 0x620d750>
sage: ax.set_xlim3d(-3, 2)
(-3, 2)
sage: ax.w_xaxis.get_major_locator()._integer = True
sage: for t in ax.w_xaxis.get_ticklabels(): t.set_fontsize(6)
....:
sage: plt.savefig('/tmp/my_figure.pdf', bbox_inches='tight')

more