如何将笛卡尔坐标轴添加到 matplotlib 中的极坐标图?
How do I add cartesian axes to a polar plot in matplotlib?
我有一个极坐标图,我想给它添加笛卡尔轴。我怎样才能做到这一点?似乎没有这方面的文档。
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)
x = np.linspace(0, 8, 50)
y = np.linspace(0, 8, 40)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig, ax = plt.subplots(subplot_kw = dict(projection = 'polar'))
plt.axis('off')
ax.contourf(X, Y, Z)
要将笛卡尔坐标轴添加到极坐标图中,您所要做的就是在相同位置添加第二对坐标轴,如下所示:
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)
x = np.linspace(0, 8, 50)
y = np.linspace(0, 8, 40)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig, ax = plt.subplots(subplot_kw = dict(projection = 'polar'))
plt.axis('off')
ax.contourf(X, Y, Z)
new_axis = fig.add_axes(ax.get_position(), frameon = False)
new_axis.plot()
plt.show()
我有一个极坐标图,我想给它添加笛卡尔轴。我怎样才能做到这一点?似乎没有这方面的文档。
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)
x = np.linspace(0, 8, 50)
y = np.linspace(0, 8, 40)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig, ax = plt.subplots(subplot_kw = dict(projection = 'polar'))
plt.axis('off')
ax.contourf(X, Y, Z)
要将笛卡尔坐标轴添加到极坐标图中,您所要做的就是在相同位置添加第二对坐标轴,如下所示:
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)
x = np.linspace(0, 8, 50)
y = np.linspace(0, 8, 40)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig, ax = plt.subplots(subplot_kw = dict(projection = 'polar'))
plt.axis('off')
ax.contourf(X, Y, Z)
new_axis = fig.add_axes(ax.get_position(), frameon = False)
new_axis.plot()
plt.show()