Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wedged polar plot's position/scaling leaves too much white space. #10264

Open
Labels
keepItems to be ignored by the “Stale” Github Actiontopic: polar
@ImportanceOfBeingErnest

Description

Coming fromthis 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 usefloating 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:

importnumpyasnpimportmatplotlib.pyplotaspltfig,axes=plt.subplots(1,2,subplot_kw={'projection':'polar'},figsize=(8,4))fori,theta_maxinenumerate([2*np.pi,np.pi]):# define theta vector with varying end point and some data to plottheta=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.

image

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.

importmatplotlib.pyplotaspltfig,ax=plt.subplots(1,1,figsize=(6,3.4),subplot_kw={'projection':'polar'})# set 'thetamin' and 'thetamax' according to dataax.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.

image

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.

importmatplotlib.pyplotaspltfig,ax=plt.subplots(1,1,figsize=(6,3.4),subplot_kw={'projection':'polar'})# set 'thetamin' and 'thetamax' according to dataax.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: polar

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp