I am having an issue plotting a polar equation in python using matplotlib.
The way I understand it, I am to create a variable that represents theta.. or all angles that is to be used in the plot. In my case from 0 to 2(pi), with 1000 steps in between.
Then I should just be able to input the polar equation as R and, plot it.
My issue is that I know this equation* is supposed to be a circle. But my code does not plot a circle.
*r = 2sinθ + 2cosθ
Here is what is produces by wolfram alpha, which I know is the correct graph, vs my result
Wolfram Alpha Expected graph
Result of my python code Python output
Now if I change r to be this instead:
r = abs(2 * np.cos(theta) + 2 * np.sin(theta))
The graph produced is as shown here
This graphs "top half" is what i expect from my original code, and cannot figure out why the graph produces a cardioid instead of a circle
import numpy as np
from matplotlib import pyplot as plt
#Produce theta variable
theta = np.arange(0, 2*np.pi, .01)[1:]
#Input polar equation of 2sinθ + 2cosθ
r = 2 * np.cos(theta) + 2 * np.sin(theta)
# Adding "()" around eq doesn't change anything
#Make plt figure
fig = plt.figure()
#Make sub-plot with attribute "polar"
ax = fig.add_subplot(polar=True)
#Plot function
ax.plot(theta, r)
#Show plot
plt.show()




ax.plot(t, r)byax.plot(t+(r<0)*np.pi, np.abs(r))for the reason explained in the second link provided by @Stef.(t = np.linspace(0, 2*np.pi, 120))