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")
Assuming you want to rotate by a multiple of 90 degrees, you can set the rotation of a polar plot by setting the ThetaZeroLocation , which sets where on the plot the zero angle is located. By default this is set to 'left' -- you can change this to one of 'left' , 'right' , 'bottom' , or 'top' .
Create Polar PlotPlot a line in polar coordinates and add a title. Before R2022a, polar axes do not include degree symbols by default. To add them, get the polar axes using pax = gca . Then modify the tick labels using pax.
To plot a point in the form(r,θ),θ>0, ( r , θ ) , θ > 0 , move in a counterclockwise direction from the polar axis by an angle of θ, and then extend a directed line segment from the pole the length of r in the direction of θ.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With