Skip to content

Instantly share code, notes, and snippets.

@Quar
Last active November 23, 2016 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quar/e80e2dcf5323b018151145274ac42b1d to your computer and use it in GitHub Desktop.
Save Quar/e80e2dcf5323b018151145274ac42b1d to your computer and use it in GitHub Desktop.
seaborn.pairplot can have its legend crushing on the right edge of the subplots on macOS. This shows a temporary solution.
import seaborn as sns
sns.set()
# turn on interactive mode, avoid-blocking
sns.plt.ion()
# take iris scatterplot matrix as an example
iris = sns.load_dataset("iris")
# plot with conda bulit matplotlib-1.5.3-np111py35_1 and seaborn-0.7.1-py35_0
# legend is crushing on the right edge of subplots
sns.pairplot(iris, hue="species")
# investigating the right margin of subplot parameters
sns.plt.gcf().subplotpars.right
# will return: 0.98875156054931335
# while the documented default value is 0.9, according to
# http://matplotlib.org/api/figure_api.html#matplotlib.figure.SubplotParams
# the value of right margin might be changed by matplotlib.pyplot.tight_layout()?
# reset the right margin of subplot to its documented default value will temporarily solve the crushing issue.
sns.plt.gcf().subplots_adjust(right=0.9) # you can further reduce the value to separate legend and subplots.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment