對于一項任務,我正在嘗試重新創建玫瑰圖

這是我的代碼:
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')

有沒有辦法讓它看起來更接近原始情節(例如,讓花瓣變窄,將刻度線設定為 0.0、0.5、1.0)?
uj5u.com熱心網友回復:
您可以對這種型別的繪圖使用極坐標投影:
- 對于刻度,它由
rticks - 對于花瓣,它由
nmax特征控制
這是一個提供更好繪圖的代碼:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415794.html
標籤:
下一篇:繪制許多彩色矩形
