xpsi-group / xpsi

X-PSI: X-ray Pulse Simulation and Inference
Other
34 stars 20 forks source link

Tight layout not working with corner plots #314

Closed thjsal closed 1 year ago

thjsal commented 1 year ago

The tight layout is not working with large corner plots for the Python3 version of X-PSI. The reason for that is not clear to me. This means that for large corner plots vertical white spaces appear between the subplots unless rotating the x-axis tick labels by 90 degrees using axis_tick_x_rotation option. An example of this is the first corner plot in the Post-processing tutorial: https://xpsi-group.github.io/xpsi/Post-processing.html. This did not happen with the older GetDist and X-PSI versions used with Python2.

I have tried to fix the problem by adding plt.tight_layout() after calling the CornerPlotter, but that does not seem to help (it just gives a warning that a tight layout is not possible). In addition, passing tight_layout=True keyword argument for GetDist does not affect either. In this case, GetDist documentation (https://getdist.readthedocs.io/en/latest/plots.html) suggests trying constrained_layout=Trueargument instead. That does not remove vertical white spaces, and it even creates horizontal white spaces between the subplots instead.

thjsal commented 1 year ago

Seems like there as been changes in GetDist which explain the different behavior now. Here is link to the issue I raised there: https://github.com/cmbant/getdist/issues/102

thjsal commented 1 year ago

As mentioned in the (now closed) GetDist issue linked above, the tight layout can be achieved by decreasing the font size or rotating the tick labels.

But if don't want to do that, one can still get tight layout by modifying GetDist (getdist/getdist/plots.py) by replacing line self.gridspec.tight_layout(self.fig, h_pad=self._share_kwargs.get('h_pad'), w_pad=self._share_kwargs.get('w_pad'), rect=rect) with plt.tight_layout(h_pad=self._share_kwargs.get('h_pad'), w_pad=self._share_kwargs.get('w_pad'), rect=rect).

Since making this change did not get support from GetDist, I consider this issue closed.