r/learnpython • u/_between3-20 • 4d ago
Remove padding of polar subplots
I have a figure that is composed of many subplots. Some of them are just simple plots with a normal projection, but some are made with a polar projection. I have it set up such that there are no labels on the outside of the polar plots, but when I look at the final figure, I still get tiny plots compared to the other ones because there is a lot of padding kept on the margins of the polar subplots. I have already tried passing the pad=0 option while plotting, as well as using plt.subplots_adjust() or plt.tight_layout(), but I still get comparatively smaller radar plots. I could fix this manually using an external editor, but I would like to be able to solve it using Python on its own.
1
u/TheRNGuy 4d ago
You need to look in browser web dev tool.
It could come from completely different thing (look in layout and in css tabs)
You can also change things in real time there to find problem faster.
1
u/kimiyah_Fremiot 4d ago
Are your subplot cells rectangular by chance? Polar plots stay strictly circular, so they shrink to match the smaller dimension of the grid cell and leave whitespace on the longer side regardless of your padding settings
1
u/Asly97 4d ago
pad and tight_layout won't touch it because that space isn't padding. A polar axes is locked to a circle, so it can only be as big as the shorter side of its grid cell. If your cells are wider than they are tall, the circle fits the height and the leftover width just sits empty, while the normal plots stretch to fill the whole rectangle. Next to each other the radar plots look tiny.
In a quick test with a 2x3 grid (polar in the middle column) this made them all the same size:
set_box_aspect(1) makes the normal plots square too, so they match the circles, and layout="compressed" (matplotlib 3.6 or newer) closes up the gaps around fixed-aspect axes, which tight_layout doesn't do.
If you want to keep the normal plots wide, the other route is giving the polar ones square cells, e.g. put them in their own row, or play with height_ratios / width_ratios in add_gridspec until the polar cells come out roughly square. Then each circle fills its cell.
There's also ax.set_aspect("auto") on the polar axes, which fills the cell but squashes the circle into an oval, so probably not what you want in a printed report.