Description
Coming from this stackoverflow question, some strange (to me) behaviour is observed when plotting partial or wedged polar plots. This new feature, which can be used by setting .set_thetamin
and .set_thetamax
on a polar plot, allows to plot only part of a polar plot without the need to use floating axes - which is of course a great feature.
The problem arises when either using those partial polar plots as subplots or when trying to plot them tightly in a figure. It seems like their position is always set to be in the middle of some kind of subplot with aspect ratio of 1. Especially when using a half circle polar plot, this causes a lot of unnecessary white space around the half-circle.
Consider this code:
import numpy as np
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, subplot_kw={'projection': 'polar'},
figsize=(8, 4))
for i, theta_max in enumerate([2*np.pi, np.pi]):
# define theta vector with varying end point and some data to plot
theta = np.linspace(0, theta_max, 181)
axes[i].set_thetamin(0)
axes[i].set_thetamax(theta_max*180/np.pi)
axes[i].set_xlabel('Magnitude', fontsize=15)
axes[i].set_ylabel('Angles', fontsize=15)
plt.savefig("polarwedges2.svg", facecolor="#e8f4f2")
which produces the top plot in the below image. I have manually marked the region which is occupied by the polar plot, calling it "Incompressible BBox", because it occupies much more space than desired, also making the xlabel appearing totally off. The picture below is what I would expect this subplot to behave like.
The "imcompressibility" of that box also prevents to have such a half-circle polar plot tight in a figure.
In the following code a simple figure with such a plot is attempted.
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(6,3.4), subplot_kw={'projection': 'polar'})
# set 'thetamin' and 'thetamax' according to data
ax.set_thetamin(0)
ax.set_thetamax(180)
ax.set_xlabel('Magnitude', fontsize=15)
ax.set_ylabel('Angles', fontsize=15)
plt.savefig("polarwedge3.svg", facecolor="#e8f4f2")
The plot appears much smaller than the figure would allow for and leaves a lot of white space around.
The only workaround I can currently think of is to make the original axes much larger than the figure (ax.set_position( [0.1, -0.45, 0.8, 2])
) and shift the xlabel manually by some amount towards the top, as shown in the lower picture. Workaround code.
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(6,3.4), subplot_kw={'projection': 'polar'})
# set 'thetamin' and 'thetamax' according to data
ax.set_thetamin(0)
ax.set_thetamax(180)
ax.set_xlabel('Magnitude', fontsize=15, labelpad=-60)
ax.set_ylabel('Angles', fontsize=15)
ax.set_position( [0.1, -0.45, 0.8, 2])
plt.savefig("polarwedge4.svg", facecolor="#e8f4f2")
I guess this behaviour is in general undesired. One would rather have either the same behaviour as for fixed aspect plots (like imshow, i.e. what is called "compressible" above) or even better, some API to set the position to useful values according to the usual subplot mechanism.