Python code for graphing a rose curve

788 Views Asked by At

I am having trouble running the following code in Jupyter notebook.

import matplotlib.pyplot as plt
import math
  
plt.axes(projection='polar')
  
a = 1
n = 6
rads = np.arange(0, (2 * np.pi), 0.01) 
  
for rad in rads:
    r = a*np.cos(n*rad)
    plt.polar(rad, r, 'g.')

plt.show() 

'''

This is my attempt(to be honest, copied it from an online source) to graph a rose curve $r= \cos{6\theta}$. 

Thanks for any help.
1

There are 1 best solutions below

1
On BEST ANSWER

Welcome to stack! This is a stackoverflow question. Regardless, here's a solution. Maybe it will help you before this post is deleted. You have two major issues. First, you're making many plots, not one. Each iteration of your for loop produces a plot. Second, you're making a polar projection of a polar plot, which is not necessary. Just make one polar plot.

import numpy as np
import matplotlib.pyplot as plt
a = 1
k = 6
t = np.linspace(0,2*np.pi,1000) 
r = a*np.cos(k*t)
plt.polar(t,r)