繁体   English   中英

如何在极坐标图周围添加环绕轴?

[英]How to add an encircling axes around a polar plot?

我正在试图弄清楚如何将轴附加到我的极地投影上。 新添加的轴应该像环一样环绕原始极轴。

为此目的,我试图用append_axes从通过创建一个分频器make_axes_locatablepolar matplotlib投影ax

但是,对于“外部”或任何与append_axes参数类似极坐标投影的东西,没有选择。 我没有围绕轴的环,而是在原始轴下方获得一个新轴(见图)。

有没有可以在现有极轴周围创建环形轴的替代方案?

注意,我不想将它们添加到同一个轴上,因为比例可能不同。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

plt.style.use("seaborn-white")
def synthesize(polar=False):
    fig = plt.figure()
    ax = fig.add_subplot(111, polar=polar)
    t = np.linspace(0,2*np.pi)
    r_sin = np.sin(t)
    r_cos = np.cos(t)
    for r in [r_sin, r_cos]:
        ax.scatter(t, r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
        ax.scatter(t, -r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
    ax.set_title("polar={}".format(polar),fontsize=15)
    ax.set_xticklabels([])
    return fig, ax, t

# Rectilinear
fig, ax, t = synthesize(polar=False)
# Here are the plot dimensions in response to the answer below
xlim = ax.get_xlim()
ylim = ax.get_ylim()
rlim = (ax.get_rmin(), ax.get_rmax())
print(xlim, ylim, rlim)
(0.0, 6.283185307179586) (0.0, 2.2437621373846617) (0.0, 2.2437621373846617)
# Encircling axis
divider = make_axes_locatable(ax)
ax_below = divider.append_axes("bottom", size="32.8%", pad=0.1)
ax_below.scatter(t, np.tan(t), c="black", edgecolor="white")

# Polar
fig, ax, t = synthesize(polar=True)
divider = make_axes_locatable(ax)
ax_below = divider.append_axes("bottom", size="32.8%", pad=0.1)
ax_below.scatter(t, np.tan(t), c="black", edgecolor="white")

在此输入图像描述

您可以通过像这样set_rmaxset_rorigin来做一些事情:

import numpy as np
import matplotlib.pyplot as plt

plt.style.use("seaborn-white")
def synthesize(polar=False):
    fig = plt.figure()
    ax = fig.add_subplot(111, polar=polar)
    ax.set_rmax(30)
    t = np.linspace(0,2*np.pi)
    r_sin = np.sin(t)
    r_cos = np.cos(t)
    for r in [r_sin, r_cos]:
        ax.scatter(t, r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
        ax.scatter(t, -r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
    ax.set_title("polar={}".format(polar),fontsize=15)
    ax.set_xticklabels([])
    return fig, ax, t

# Polar
fig, ax, t = synthesize(polar=True)
ax_below = fig.add_subplot(111, polar=True, frameon=True)

# ax_below = divider.append_axes("bottom", size="32.8%", pad=0.1)
ax_below.scatter(t, np.tan(t), c="black", edgecolor="white")
ax_below.set_rorigin(-75)
ax_below.set_rmin(-25)
plt.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM