Matplotlib 插图极坐标图

Nic*_*llo 1 python matplotlib

我试图在笛卡尔坐标中的正常 x 与 y 图中插入极坐标图。我知道插图可以通过 pylab.axes 获得,如本所示。但我不知道如何指定这是一个极坐标图,可能没有任何网格。欢迎任何帮助

joa*_*uin 6

这里有一个工作示例。
要点是为第二个图形指定一个新的、更小的轴

import numpy as np
from matplotlib import pyplot as plt
from scipy import randn, convolve

#data
t = np.arange(0.0, 20.0, 0.001)
r = np.exp(-t[:1000]/0.05)     
x = randn(len(t))
s = convolve(x,r)[:len(x)]*0.001
theta = 2 * np.pi * t
#
fig = plt.figure(figsize=(7, 6))
#main
plt.plot(t, s)
plt.axis([0, 1, np.amin(s), 2.5*np.amax(s)])
plt.xlabel('xlabel')
plt.ylabel('ylabel')
#polar
ax = fig.add_axes([0.2, 0.47, 0.30, 0.40], polar=True, axisbg='yellow')
ax.plot(theta, t, color='blue', lw=3)
ax.set_rmax(1.0)
plt.grid(True)

plt.show()    
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述