Matplotlib 内嵌极坐标图

1 投票
1 回答
3947 浏览
提问于 2025-04-17 03:26

我想在一个普通的x和y的图上插入一个极坐标图。我知道可以通过pylab.axes来实现这个插入,就像这个例子展示的那样。但是我不知道怎么指定这个插入的是一个极坐标图,而且可能不需要任何网格。欢迎任何帮助!

1 个回答

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()    

在这里输入图片描述

撰写回答