mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.56k stars 1.92k forks source link

sns.pairplot not working in 0.12.0 #3085

Closed sorenwacker closed 2 years ago

sorenwacker commented 2 years ago

Seaborn version: 0.12.0 Pandas version: 1.4.4 Numpy version: 1.22.4 Patplotlib version: 3.6.1

import pandas as pd
import seaborn as sns

json = '{"PC-1":{"CA_1.mzXML":3.0813660073,"CA_2.mzXML":1.5498711715,"CA_3.mzXML":-2.2502639446,"CA_4.mzXML":-2.3809732342},"PC-2":{"CA_1.mzXML":-0.9837774178,"CA_2.mzXML":1.3379986935,"CA_3.mzXML":0.8741636925,"CA_4.mzXML":-1.2283849681},"PC-3":{"CA_1.mzXML":0.2164062363,"CA_2.mzXML":-0.3125695473,"CA_3.mzXML":0.3563478905,"CA_4.mzXML":-0.2601845795}}'

df =pd.read_json(json)

image

g = sns.pairplot(data=df)


---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
Cell In [20], line 1
----> 1 g = sns.pairplot(data=df)

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/seaborn/axisgrid.py:2144, in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, height, aspect, corner, dropna, plot_kws, diag_kws, grid_kws, size) 2142 diag_kws.setdefault("legend", False) 2143 if diag_kind == "hist": -> 2144 grid.map_diag(histplot, **diag_kws) 2145 elif diag_kind == "kde": 2146 diag_kws.setdefault("fill", True)

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/seaborn/axisgrid.py:1507, in PairGrid.map_diag(self, func, kwargs) 1505 plot_kwargs.setdefault("hue_order", self._hue_order) 1506 plot_kwargs.setdefault("palette", self._orig_palette) -> 1507 func(x=vector, plotkwargs) 1508 ax.legend = None 1510 self._add_axis_labels()

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/seaborn/distributions.py:1418, in histplot(data, x, y, hue, weights, stat, bins, binwidth, binrange, discrete, cumulative, common_bins, common_norm, multiple, element, fill, shrink, kde, kde_kws, line_kws, thresh, pthresh, pmax, cbar, cbar_ax, cbar_kws, palette, hue_order, hue_norm, color, log_scale, legend, ax, **kwargs) 1416 else: 1417 method = ax.plot -> 1418 color = _default_color(method, hue, color, kwargs) 1420 if not p.has_xy_data: 1421 return ax

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/seaborn/utils.py:139, in _default_color(method, hue, color, kws) 134 scout.remove() 136 elif method.name == "bar": 137 138 # bar() needs masked, not empty data, to generate a patch --> 139 scout, = method([np.nan], [np.nan], **kws) 140 color = to_rgb(scout.get_facecolor()) 141 scout.remove()

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/matplotlib/init.py:1423, in _preprocess_data..inner(ax, data, *args, kwargs) 1420 @functools.wraps(func) 1421 def inner(ax, *args, data=None, *kwargs): 1422 if data is None: -> 1423 return func(ax, map(sanitize_sequence, args), kwargs) 1425 bound = new_sig.bind(ax, *args, **kwargs) 1426 auto_label = (bound.arguments.get(label_namer) 1427 or bound.kwargs.get(label_namer))

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/matplotlib/axes/_axes.py:2373, in Axes.bar(self, x, height, width, bottom, align, **kwargs) 2371 x0 = x 2372 x = np.asarray(self.convert_xunits(x)) -> 2373 width = self._convert_dx(width, x0, x, self.convert_xunits) 2374 if xerr is not None: 2375 xerr = self._convert_dx(xerr, x0, x, self.convert_xunits)

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/matplotlib/axes/_axes.py:2182, in Axes._convert_dx(dx, x0, xconv, convert) 2170 try: 2171 # attempt to add the width to x0; this works for 2172 # datetime+timedelta, for instance (...) 2179 # removes the units from unit packages like pint that 2180 # wrap numpy arrays. 2181 try: -> 2182 x0 = cbook._safe_first_finite(x0) 2183 except (TypeError, IndexError, KeyError): 2184 pass

File ~/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/matplotlib/cbook/init.py:1749, in _safe_first_finite(obj, skip_nonfinite) 1746 raise RuntimeError("matplotlib does not " 1747 "support generators as input") 1748 else: -> 1749 return next(val for val in obj if safe_isfinite(val))

StopIteration: /home/swacker/miniconda3/envs/ms-mint-py310/lib/python3.10/site-packages/IPython/core/pylabtools.py:151: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. fig.canvas.print_figure(bytes_io, **kw)

sorenwacker commented 2 years ago

Strangely, I am getting the same error with the demo code.

penguins = sns.load_dataset("penguins")
sns.pairplot(penguins)
sorenwacker commented 2 years ago

It works with matplotlib 3.5.2.

mwaskom commented 2 years ago

Please see the pinned issue with the same error message in its title.