📜  Python中的 matplotlib.pyplot.polar()

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

Python中的 matplotlib.pyplot.polar()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 PyplotMatplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。

matplotlib.pyplot.polar()函数:

matplotlib 库的 pyplot 模块中的polar()函数用于制作极坐标图。

下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.polar()函数:

示例 #1:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import numpy as np
   
from matplotlib.transforms import offset_copy
   
xs = np.arange(-2, 2)
ys = np.cos(xs**2)
plt.polar(xs, ys) 
   
plt.title('matplotlib.pyplot.polar() function Example',
                                    fontweight ="bold")
plt.show()

输出:

示例 #2:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import numpy as np
  
from matplotlib.transforms import offset_copy
  
xs = np.arange(8)
ys = np.cos(xs**2)
  
fig = plt.figure(figsize =(5, 10))
ax = plt.subplot(1, 1, 1)
  
trans_offset = mtransforms.offset_copy(ax.transData, fig = fig,
                                       y = 6, units ='dots')
  
for x, y in zip(xs, ys):
    plt.polar(x, y, 'go')
    plt.text(x, y, '% d, % d' % (int(x), int(y)),
                       transform = trans_offset,
                  horizontalalignment ='center',
                    verticalalignment ='bottom')
      
plt.title('matplotlib.pyplot.polar() function Example', 
                                    fontweight ="bold")
plt.show()

输出: