Skip to content Skip to sidebar Skip to footer

Matplotlib Unexpected Results Polar Plot

I am trying to plot simple function r = 3*sin(2*theta) using matplotlib: import numpy as np import matplotlib.pyplot as plt theta = np.arange(0,2*np.pi,0.01) r = 3.0*np.sin(2.0*the

Solution 1:

this patches the polar plot for neg r

import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0,2*np.pi,0.01)
r = 3.0*np.sin(2.0*theta)
theta = theta + (1 - np.sign(r))*np.pi/2 # add pi to points with negative r values
r = np.abs(r) # make all r values postive to fake out matplotlib
ax = plt.subplot(111, projection='polar')
ax.plot(theta, r)
plt.show()

Post a Comment for "Matplotlib Unexpected Results Polar Plot"