ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 04 Oct 2011 06:29:40 +0200point3d label axeshttps://ask.sagemath.org/question/8356/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[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.
Mon, 03 Oct 2011 08:13:38 +0200https://ask.sagemath.org/question/8356/point3d-label-axes/Comment by kcrisman for <p>Hi,</p>
<p>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.</p>
<p>here is what I am doing in the sage command line:</p>
<pre><code>from matplotlib.mlab import PCA
pca_info=PCA(data)
a=point3d(pca_info.Wt[:3,])
a.show()
</code></pre>
<p>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 </p>
<pre><code>axes_labels(['x','y','z'])
</code></pre>
<p>But I when trying the following, I get an attribute error</p>
<pre><code>a.axes_labels(['PCA1 (%0.3f)' %pca_info.fracs[0],
'PCA2 (%0.3f)' %pca_info.fracs[1],
'PCA3 (%0.3f)' %pca_info.fracs[2]])
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/8356/point3d-label-axes/?comment=21174#post-id-21174Yeah, 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?Mon, 03 Oct 2011 09:29:09 +0200https://ask.sagemath.org/question/8356/point3d-label-axes/?comment=21174#post-id-21174Comment by PJ for <p>Hi,</p>
<p>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.</p>
<p>here is what I am doing in the sage command line:</p>
<pre><code>from matplotlib.mlab import PCA
pca_info=PCA(data)
a=point3d(pca_info.Wt[:3,])
a.show()
</code></pre>
<p>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 </p>
<pre><code>axes_labels(['x','y','z'])
</code></pre>
<p>But I when trying the following, I get an attribute error</p>
<pre><code>a.axes_labels(['PCA1 (%0.3f)' %pca_info.fracs[0],
'PCA2 (%0.3f)' %pca_info.fracs[1],
'PCA3 (%0.3f)' %pca_info.fracs[2]])
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/8356/point3d-label-axes/?comment=21172#post-id-21172Thanks for the info, it seems I have to use sage with something else, maybe something like mayavi. Mon, 03 Oct 2011 16:33:10 +0200https://ask.sagemath.org/question/8356/point3d-label-axes/?comment=21172#post-id-21172Answer by Volker Braun for <p>Hi,</p>
<p>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.</p>
<p>here is what I am doing in the sage command line:</p>
<pre><code>from matplotlib.mlab import PCA
pca_info=PCA(data)
a=point3d(pca_info.Wt[:3,])
a.show()
</code></pre>
<p>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 </p>
<pre><code>axes_labels(['x','y','z'])
</code></pre>
<p>But I when trying the following, I get an attribute error</p>
<pre><code>a.axes_labels(['PCA1 (%0.3f)' %pca_info.fracs[0],
'PCA2 (%0.3f)' %pca_info.fracs[1],
'PCA3 (%0.3f)' %pca_info.fracs[2]])
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/8356/point3d-label-axes/?answer=12719#post-id-12719Apart 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')
Tue, 04 Oct 2011 06:29:40 +0200https://ask.sagemath.org/question/8356/point3d-label-axes/?answer=12719#post-id-12719