Home > Back-end >  Python: Recreating rose plot
Python: Recreating rose plot

Time:01-14

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

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)?

CodePudding user response:

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
  •  Tags:  
  • Related