matplotlib.pyplot.polar函数绘制极坐标图
Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Pyplot是一个基于状态的Matplotlib模块接口,该模块提供了一个类似matlab的接口。
matplotlib.pyplot.polar()函数:
使用matplotlib库pyplot模块中的polar()函数绘制极坐标图。
语法:matplotlib.pyplot.polar (* args, * * kwargs)
参数:此方法不接受任何参数。
返回:此方法不返回任何值。
下面的例子演示了matplotlib.pyplot.polar()函数在matplotlib.pyplot中的作用:
示例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()
输出: