Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: Recreating rose plot

For an assignment, I am trying to recreate the rose plot
enter image description here

Here is my code:

import numpy as np
import matplotlib.pyplot as plt

nmax=101 # choose a high number to "smooth out" lines in plots
x_angle = np.linspace(0,2*np.pi,nmax) # create an array x for bottom right 
y_br = abs(np.cos(3*x_angle)) # y for the bottom right subplot

# bottom right subplot controls
plt.plot(x_angle, y_br, 'tab:blue')

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a way to get it to look any closer to the original plot (e.g. make the petals narrower, set tick marks to 0.0, 0.5, 1.0)?

>Solution :

You can use polar projection for this type of plot:

  • for the ticks, it is set by rticks
  • for the petals, it is controlled by the nmax feature

Here is a code that gives a better drawing:

import numpy as np
import matplotlib.pyplot as plt

nmax=int(1e5) # choose a high number to "smooth out" lines in plots
x_angle = np.linspace(0,2*np.pi,nmax) # create an array x for bottom right 
y_br = abs(np.cos(3*x_angle)) # y for the bottom right subplot

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.plot(x_angle, y_br, lw= 3)
ax.set_rticks([0, 0.5, 1])  # Less radial ticks
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading