Ask Your Question

point3d label axes

asked 2011-10-03 08:13:38 +0200

PJ gravatar image


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

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


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

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

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 flag offensive close merge delete


Yeah, 3d plots and certain labels are not as far along as we'd like. It is possible ( to use text3d if you are lucky with positioning, perhaps?

kcrisman gravatar imagekcrisman ( 2011-10-03 09:29:09 +0200 )edit

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

PJ gravatar imagePJ ( 2011-10-03 16:33:10 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2011-10-04 06:29:40 +0200

Volker Braun gravatar image

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')
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-10-03 08:13:38 +0200

Seen: 1,867 times

Last updated: Oct 04 '11