2

I have this 3D graph

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d

t = np.linspace(0,2*np.pi, 40)

# Position equations
def rx(t):
    return t * np.cos(t)
def ry(t):
    return t * np.sin(t)

fig = plt.figure(figsize=(10,10))
axes = fig.gca(projection='3d')

While the graph works, I'm trying to label t at certain points in my graph but it is not showing up.

For example, trying to label t=2pi/3 as a text.

axes.plot(rx(t), ry(t), t, c='k')
axes.annotate(r'$t = 3 \pi/2$', xy=(rx(3*np.pi/2), ry(3*np.pi/2))
plt.xlim(-2*np.pi,2*np.pi)    
plt.ylim(-6,6)
plt.show

enter image description here

Does anyone know how to fix this problem?

iron2man
  • 1,787
  • 5
  • 27
  • 39
  • See the answers here: http://stackoverflow.com/questions/10374930/matplotlib-annotating-a-3d-scatter-plot ; looks like 3d doesn't really support `annotate`, but you can use the `text` method. – cphlewis Jan 27 '16 at 06:56
  • @ cphlewis hmm, that seems annoying. I'll see what i can do then. – iron2man Jan 27 '16 at 13:37
  • Your question says you are trying to label `t=2pi/3`, but the code says `3*np.pi/2` – OneCricketeer Jan 27 '16 at 16:56
  • While that is true, i meant to label the point as a text. I'll edit for clarity. – iron2man Jan 27 '16 at 17:04

1 Answers1

2

Just took from this answer and made some tweaks to the text size.

The string that labels the points is '{:>10f}'.format(t_val), which you can change to whatever you want.

t_values = [np.pi/3, 2*np.pi/3, np.pi]
for t_val in t_values:
    axes.scatter(rx(t_val),ry(t_val),t_val,color='r') 
    axes.text(rx(t_val),ry(t_val),t_val,'{:>10f}'.format(t_val), size=10, zorder=1, color='k') 

axes.plot(rx(t), ry(t), t)

Point labels

Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245