Plotting planet speed in Python using matplotlib and quantities: RuntimeError
Question: I am writting a program in python to plot planet's distances to the Sun vs
orbital velocity. No problem with that. Then I have to plot in the same graph,
a line with the function: v = GMsun/r, where v is orbital speed, G is Newton's
Gravitational constant, Msun the mass of the Sun and r is distance. I use
quantities library to keep dimensional consistency between units. When I try
to plot that function, I get this error. Could you tell me where is the error?

    
    
    import numpy as np 
    import matplotlib.pyplot as plt 
    import quantities as pq
    
    #orbital velocity (km/s)
    velocity= np.array([47.8725, 35.021, 29.7859, 24.130, 13.0697, 9.6724, 6.8352, 5.4778])
    
    #Distance (UA)
    distance = np.array([0.38709893, 0.72333199, 1., 1.52366231, 5.20336301, 9.53707032, 19.19126393, 30.06896348])
    
    #Normalize so distance to Earth = 1
    velocity2 = velocity / (29.7859)
    
    #Calculate the equation:
    Msun = 1.9891e30 * pq.kg #Sun mass
    G = 1 * pq.constants.G #Gravitational constant
    
    r = np.arange(0.1,34,0.1) * pq.au #Distance to Sun in Astronomical Units
    Vc = np.sqrt(G*Msun/ r) #equation
    Vc2 = Vc.rescale(pq.km / pq.s) / 29.7859 #convert to km/s and normalize to Earth's speed.
    #Plotting:
    
    fig = plt.figure() 
    plt.plot(distance, velocity2, 'ro')
    plt.plot(r, Vc2, 'b-')
    plt.ylabel(r'Orbital Velocity (km/s)', fontsize = 18)
    plt.xlabel(r'Distance to Sun (AU)', fontsize = 18)
    
    
    plt.show()
    

The error doesn't show if I coment the line plt.plot(r, Vc2, 'b-'). the error
is this, the first line repeats a lot, so I only show irt once:

    
    
    File "/usr/lib64/python2.7/site-packages/matplotlib/units.py", line 148,  in get_converter
    converter = self.get_converter(xravel[0])
    File "/usr/lib/python2.7/site-packages/quantities/quantity.py", line 352, in __getitem__
    return Quantity(ret, self._dimensionality)
    File "/usr/lib/python2.7/site-packages/quantities/quantity.py", line 126, in __new__
    ret = np.array(data, dtype=dtype, copy=copy).view(cls)
    File "/usr/lib/python2.7/site-packages/quantities/quantity.py", line 215, in __array_finalize__
    self._dimensionality = getattr(obj, 'dimensionality', Dimensionality())
    RuntimeError: maximum recursion depth exceeded while calling a Python object
    [Finished in 8.6s with exit code 1]
    

Thanks so much.


Answer: OK SOLVED: just removed and reinstalled pyplot, and everything runs fine now.
Thanks.

