简体   繁体   中英

How to add an encircling axes around a polar plot?

I'm trying to figure out how to append an axes to my polar projection. The newly added axes is supposed to wrap around the original polar axes like a ring.

For that purpose I tried to use append_axes from a divider created via make_axes_locatable on a polar matplotlib projection ax .

However, there's no option for "outer" or anything that would resemble polar projections with the append_axes arguments. Instead of a ring around the axes, I get a new axes just below the original one (see picture).

Is there any alternative that would allow creating an axes of ring shape around an existing polar axes?

Note, I don't want to add them on the same ax because the scales may be different.

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

在此输入图像描述

You probably can do something by tunning set_rmax and set_rorigin like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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