8

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

enter image description here

O.rka
  • 29,847
  • 68
  • 194
  • 309
  • 2
    I reworded your question, such that it doesn't ask for something that is simply not possible, i.e. instead of "How do I do ?", you'd ask "How do I get ? I tried , but it fails." – ImportanceOfBeingErnest Feb 21 '19 at 21:56
  • This wording sounds much better! Thank you. I wasn't aware that the method above is specific for rectangular plots. – O.rka Feb 21 '19 at 21:59

1 Answers1

2

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()
vlizana
  • 2,962
  • 1
  • 16
  • 26
  • How did you decide on using the -25, -75, and 30 values? – O.rka Feb 24 '19 at 02:34
  • 1
    Just by trial and error, the -25 because the lower plot seems to go from -25 to 25, the -75 means that the center of the circle is at the point -75, along qith the -25 leaves 50 units to the plot in the bottom. It definetly depends on what you want to show in the plot though. – vlizana Feb 24 '19 at 03:22
  • I'm wondering there is a good way to automate it w/ the ax.get_xlim() style methods? – O.rka Feb 24 '19 at 03:38