From: Tony Yu <ts...@gm...> - 2011-05-06 15:56:46
|
On Fri, May 6, 2011 at 5:55 AM, Chris Rodgers <chr...@be...>wrote: > The real solution of course is to calculate exactly where every piece > of text actually is, detect overlaps, and adjust. That is certainly > beyond my ability or inclination to implement. In the mean time, it > would be nice to have a simple "idiot-proof" flag that blindly fixes > some common problems. > I wrote a helper script awhile back to adjust spacing "automatically". Code can be found here: http://www.mail-archive.com/mat...@li.../msg18107.html You can simply copy the code into a module (e.g. layout.py) that lives in your python path, and then call "layout.tight_layout()" *right before* your call to "plt.show()" (or "plt.savefig()"). It's pretty inefficient though because it has to draw the figure 3 different times (once to calculate the size of subplots and again to calculate the size of the figure, and then the final draw). There are some other issues, which prevent inclusion in matplotlib (see discussion in link below), but it works well for my purposes. Best, -Tony Original post, with some discussion, can be found here: http://www.mail-archive.com/mat...@li.../msg06896.html Note the code from the original post didn't work on some backends, so it's probably best to use the code from the first link. |