1

I have some very long xtick labels in a seaborn clustergram object and that I want to display in entirety. They get cut off by default. How do I adjust the margins/padding to account for this?

This did not work:

hm = sns.clustermap(df)
fig = hm.fig
fig.subplots_adjust(bottom=0.01)
fig.tight_layout(rect=[0, 0.03, 1, 0.95],pad=2)
fig.show()

And also throws a warning:

UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  warnings.warn("This figure includes Axes that are not compatible "

I have done sns.set(font_scale=0.5) but this does not sufficiently address the problem.

Update I was using subplots_adjust() incorrectly, and as pointed out in the comments, tight_layout() is not necessary. This works:

hm = sns.clustermap(df)
fig = hm.fig
fig.subplots_adjust(bottom=0.3)
fig.show()
andbeonetraveler
  • 693
  • 3
  • 11
  • 25
  • 1
    We can't know what exact problem you face without a fully runnable code, but clearly `fig.tight_layout` doesn't work for seaborn clustermaps, so you can just specify the subplot parameters manually, `fig.subplots_adjust(left=0.3, right=0.7)` or whatever suits your needs. Possible duplicate of [this](https://stackoverflow.com/a/4066599/4124317). – ImportanceOfBeingErnest Feb 14 '19 at 17:39
  • 1
    Note that in principle you can call `g.gs.tight_layout(g.fig)` but that will add space in the figure where you wouldn't want to have it. – ImportanceOfBeingErnest Feb 14 '19 at 17:41

0 Answers0