brokenaxes icon indicating copy to clipboard operation
brokenaxes copied to clipboard

tight_layout() support?

Open andrisecker opened this issue 6 years ago • 4 comments

Cool package! Are you planning to add fig.tight_layout() support? I get an error message: warnings.warn("This figure includes Axes that are not compatible " and the lines which break the axes get shifted (outside of the axis) when trying to use tight_layout()

andrisecker avatar Aug 02 '18 09:08 andrisecker

I like that idea. I'll look into it

bendichter avatar Aug 02 '18 12:08 bendichter

Can you clarify what the desired behavior would be? Would the gaps between the axes of the brokenaxes plot change, or just the position of the entire brokenaxes plot?

In the meantime you should be able to get your desired results by tweaking hspace and wspace in GridSpec

bendichter avatar Aug 02 '18 14:08 bendichter

The position of the entire plot. Yes I started to tweak the GridSpec

andrisecker avatar Aug 02 '18 14:08 andrisecker

I have having a hard time with BrokenAxis, with Matplotlib completely clipping the x and y labels of a plot. Tight/constrained layouts were not solving the problem (and also moving the line breaks as mentioned above.) In my case, the figure was small (2.75"x3"), where matplotlib can have a hard time placing axes into the plot area.

I eventually found that the issue is the default x & y offsets, set with the labelpad argument for BrokenAxis.set_*_axis() function. By passing GridSpec left and bottom parameters like this bax = brokenaxes.brokenaxes(xlims=((L,R) left = 0.25, bottom = 0.25) and then setting the labels as bax.set_xlabel("x label", labelpad = 0) bax.set_ylabel("y label", labelpad = 0), I got a the desired result, with labels on the figure -- the same outcome as tight_layout() would have on a simpler figure. I'm not sure whether or not there is a way to make this automatic, but this manual solution does let you use this package to create small plots that save correctly with plt.savefig().

gabeycas avatar Nov 30 '18 18:11 gabeycas

fig.tight_layout() should work now

bendichter avatar Apr 17 '24 22:04 bendichter