Hi, I'm getting the following matplotlib error when using FacetGrid with the following invocation:
g = sns.FacetGrid(final_df, col_wrap=3, col='CLONE', size=1, margin_titles=True)
g = g.map(plt.plot, "SUBJECT", "value", marker="o", ms=4)
ValueError Traceback (most recent call last)
<ipython-input-47-f7ad55c8195d> in <module>()
1 g = sns.FacetGrid(final_df, col_wrap=3, col='CLONE', size=1, margin_titles=True)
----> 2 g = g.map(plt.plot, "SUBJECT", "value", marker="o", ms=4)
3 g.set_titles(size=5)
/large/dkoppstein/env/conda3/lib/python3.4/site-packages/seaborn/axisgrid.py in map(self, func, *args, **kwargs)
727
728 # Finalize the annotations and layout
--> 729 self._finalize_grid(args[:2])
730
731 return self
/large/dkoppstein/env/conda3/lib/python3.4/site-packages/seaborn/axisgrid.py in _finalize_grid(self, axlabels)
818 self.set_axis_labels(*axlabels)
819 self.set_titles()
--> 820 self.fig.tight_layout()
821
822 def facet_axis(self, row_i, col_j):
/large/dkoppstein/env/conda3/lib/python3.4/site-packages/matplotlib/figure.py in tight_layout(self, renderer, pad, h_pad, w_pad, rect)
1663 rect=rect)
1664
-> 1665 self.subplots_adjust(**kwargs)
1666
1667
/large/dkoppstein/env/conda3/lib/python3.4/site-packages/matplotlib/figure.py in subplots_adjust(self, *args, **kwargs)
1520
1521 """
-> 1522 self.subplotpars.update(*args, **kwargs)
1523 for ax in self.axes:
1524 if not isinstance(ax, SubplotBase):
/large/dkoppstein/env/conda3/lib/python3.4/site-packages/matplotlib/figure.py in update(self, left, bottom, right, top, wspace, hspace)
219 if self.left >= self.right:
220 reset()
--> 221 raise ValueError('left cannot be >= right')
222
223 if self.bottom >= self.top:
ValueError: left cannot be >= right
It looks like this is a matplotlib issue with tight_layout; there's a workaround, e.g. here but I don't know how to apply it to the FacetGrid instance.
Without seeing your data I'd have to guess but I think something like this can happen if your titles are too big for the facets.
Indeed, your intuition is spot-on and the titles are quite large. Is there a way to decrease the size of the titles prior to plotting? I used g.set_titles(size=2), but I get the error upon creating the FacetGrid.
You could change the default axes titlesize with an rcparam context manager or start with a big plot, change the title size, and then change the figure size.
But I doubt that what you really want is titles in 2 pt font, so you might have to rethink the plot you're trying to make.
Indeed, the size=2 was just to try an arbitrarily small number to see if it worked. I'll try setting rcparam prior to instantiating the FacetGrid, thanks for the response.
Most helpful comment
Without seeing your data I'd have to guess but I think something like this can happen if your titles are too big for the facets.