📜  Python中的 Matplotlib.pyplot.thetagrids()

📅  最后修改于: 2022-05-13 01:55:07.402000             🧑  作者: Mango

Python中的 Matplotlib.pyplot.thetagrids()

Matplotlib是Python编程语言的绘图库,其数值数学模块是 NumPy。 matplotlib.pyplot是使 matplotlib 像 MATLAB 工具一样工作的命令样式函数的集合。每个 pyplot 函数都会对图形进行某些更改:例如,创建图形,在图形中创建绘图区域,在绘图区域中绘制一些线条或用标签装饰绘图等。
注意:更多信息请参考 Matplotlib 中的 Pyplot

Matplotlib.pyplot.thetagrids()

在极坐标图中设置网格线的 theta 位置。如果未传递任何参数,则返回一个元组 (lines, labels),其中lines 是径向网格线数组(Line2D 实例),labels 是刻度标签数组(Text 实例):

例子:

Python3
import matplotlib.pyplot as plt
import numpy as np
    
employee = ["Rahul", "Joy", "Abhishek",
            "Tina", "Sneha"]
  
actual = [41, 57, 59, 63, 52, 41]
expected = [40, 59, 58, 64, 55, 40]
    
# Initialing the spiderplot by 
# setting figure size and polar
# projection
plt.figure(figsize =(10, 6))
plt.subplot(polar = True)
    
theta = np.linspace(0, 2 * np.pi, len(actual))
    
# Arranging the grid into number 
# of sales into equal parts in
# degrees
lines, labels = plt.thetagrids(range(0, 360, int(360/len(employee))),
                                                         (employee))
    
# Plot actual sales graph
plt.plot(theta, actual)
plt.fill(theta, actual, 'b', alpha = 0.1)
    
# Plot expected sales graph
plt.plot(theta, expected)
    
# Add legend and title for the plot
plt.legend(labels =('Actual', 'Expected'),
           loc = 1)
plt.title("Actual vs Expected sales by Employee")
    
# Display the plot on the screen
plt.show()


输出:

python-matplotlib-thetagrid