has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
3.92k stars 210 forks source link

Grow plot area to account for axis labels? #749

Closed jwhendy closed 5 months ago

jwhendy commented 5 months ago

I'm wondering if the plot area to consider the full width of everything, including axis text. When I angle text using

p + theme(axis_text_x=element_text(angle=315, hjust=0))

... it can result in axis text that goes past the plot boundary:

image

In lieu of doing this automatically, what would my workaround be? The closest I came to was adjusting facet distance. I'm wondering if this is possibly related, as comments on that issue suggest it's tough to work with the current layout engine.

Would I need to access the current plot element_rect and set a wider width via matplotlib options?

I did find that by increasing my save out width/height, the text fit, so this might only be an issue if one is below some minimum required plot size?

Thanks for any guidance.

has2k1 commented 5 months ago

This is fixed in the current main branch for the case were the labels are cut off at the figure boundary. This is the test case. A workaround is to increase the plot_margin on the right. e.g. theme(plot_margin_right=.05).

A release is coming out in a couple of days.

But the labels in between facets can still overlap and tor this use adjust the panel_spacing.

jwhendy commented 5 months ago

Excellent, thanks as always for the prompt info! Great tip on the margin as well; I tried plot_margin= but I'm thinking that wasn't the right option, as it only let me set from 0-1. I hadn't run into plot_margin_right.