-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Description
Using seaborn.swarmplot
with proplot axes currently leads to an error. I realize that the documentation states that most seaborn plotting methods should work with proplot axes and therefore we should not expect all of them to work, but I'm mainly curious if there might be a simple workaround.
Proplot is great by the way -- thanks for the effort to create/maintain it.
Steps to reproduce
A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you.
import proplot as pplt
import seaborn as sns
tips = sns.load_dataset("tips")
fig = pplt.figure()
ax = fig.subplot()
sns.swarmplot(ax=ax, x="day", y="total_bill", data=tips)
Expected behavior: [What you expected to happen]
I would expect this to produce a plot similar to the one produced when using just seaborn and matplotlib axes.
Actual behavior: [What actually happened]
Instead the following error is raised in addition to some warnings:
/home/spencerc/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py:1376: ProPlotWarning: Failed to restrict automatic colormap normalization algorithm to in-bounds data only. Error message: boolean index did not match indexed array along dimension 1; dimension is 3 but corresponding boolean dimension is 62
points = ax.scatter(cat_pos, swarm_data, s=s, **kws)
/home/spencerc/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py:1376: ProPlotWarning: Failed to restrict automatic colormap normalization algorithm to in-bounds data only. Error message: boolean index did not match indexed array along dimension 1; dimension is 3 but corresponding boolean dimension is 19
points = ax.scatter(cat_pos, swarm_data, s=s, **kws)
/home/spencerc/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py:1376: ProPlotWarning: Failed to restrict automatic colormap normalization algorithm to in-bounds data only. Error message: boolean index did not match indexed array along dimension 1; dimension is 3 but corresponding boolean dimension is 87
points = ax.scatter(cat_pos, swarm_data, s=s, **kws)
/home/spencerc/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py:1376: ProPlotWarning: Failed to restrict automatic colormap normalization algorithm to in-bounds data only. Error message: boolean index did not match indexed array along dimension 1; dimension is 3 but corresponding boolean dimension is 76
points = ax.scatter(cat_pos, swarm_data, s=s, **kws)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-22-5939fc904540> in <module>
1 fig = proplot.figure()
2 ax = fig.subplot()
----> 3 sns.swarmplot(ax=ax, x="day", y="total_bill", data=tips)
~/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
44 )
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)
47 return inner_f
48
~/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py in swarmplot(x, y, hue, data, order, hue_order, dodge, orient, color, palette, size, edgecolor, linewidth, ax, **kwargs)
3022
3023 This function is similar to :func:`stripplot`, but the points are adjusted
-> 3024 (only along the categorical axis) so that they don't overlap. This gives a
3025 better representation of the distribution of values, but it does not scale
3026 well to large numbers of observations. This style of plot is sometimes
~/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py in plot(self, ax, kws)
1426
1427 class _CategoricalStatPlotter(_CategoricalPlotter):
-> 1428
1429 require_numeric = True
1430
~/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py in draw_swarmplot(self, ax, kws)
1419 """Make the full plot."""
1420 self.draw_swarmplot(ax, kws)
-> 1421 self.add_legend_data(ax)
1422 self.annotate_axes(ax)
1423 if self.orient == "h":
~/miniconda3/envs/fv3net/lib/python3.7/site-packages/seaborn/categorical.py in swarm_points(self, ax, points, center, width, s, **kws)
1309 # We'll figure out the swarm positions in the latter
1310 # and then convert back to data coordinates and replot
-> 1311 orig_xy = ax.transData.transform(points.get_offsets())
1312
1313 # Order the variables so that x is the categorical axis
AttributeError: 'list' object has no attribute 'get_offsets'
Equivalent steps in matplotlib
Please make sure this bug is related to a specific proplot feature. If you're not sure, try to replicate it with the native matplotlib API. Matplotlib bugs belong on the matplotlib github page.
import seaborn as sns
tips = sns.load_dataset("tips")
sns.swarmplot(x="day", y="total_bill", data=tips)
Proplot version
Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)
here.
3.2.2
0.8.1