-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boxplot errors when dodge=True
without hue
#3553
Comments
I cannot help without a reproducible example. |
Okay i will provide the test case in few moments |
I have uploaded the zip file which contains the code and the file which you can run on your machine to reproduce the error. |
Please provide the code here and ideally adapt to one of the example datasets. |
The contributing guidelines contain a list of what must be included to make a bug report actionable for maintainers: https://github.com/mwaskom/seaborn/blob/master/.github/CONTRIBUTING.md#reporting-bugs |
Didn't try it but I'm pretty sure the issue here is that you set |
In previous version 0.12 i did not provide hue and the dodge was set to True and it works but with 0.13 it did not. |
Indeed, as mentioned in the doc |
Thanks @thuiop that suggests a reprex: sns.boxplot(tips, x="tip", y="day", dodge=True) ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [87], line 1
----> 1 sns.boxplot(tips, x="tip", y="day", dodge=True)
File ~/code/seaborn/seaborn/categorical.py:1617, in boxplot(data, x, y, hue, order, hue_order, orient, color, palette, saturation, fill, dodge, width, gap, whis, linecolor, linewidth, fliersize, hue_norm, native_scale, log_scale, formatter, legend, ax, **kwargs)
1610 color = _default_color(
1611 ax.fill_between, hue, color,
1612 {k: v for k, v in kwargs.items() if k in ["c", "color", "fc", "facecolor"]},
1613 saturation=saturation,
1614 )
1615 linecolor = p._complement_color(linecolor, color, p._hue_map)
-> 1617 p.plot_boxes(
1618 width=width,
1619 dodge=dodge,
1620 gap=gap,
1621 fill=fill,
1622 whis=whis,
1623 color=color,
1624 linecolor=linecolor,
1625 linewidth=linewidth,
1626 fliersize=fliersize,
1627 plot_kws=kwargs,
1628 )
1630 p._add_axis_labels(ax)
1631 p._adjust_cat_axis(ax, axis=p.orient)
File ~/code/seaborn/seaborn/categorical.py:635, in _CategoricalPlotter.plot_boxes(self, width, dodge, gap, fill, whis, color, linecolor, linewidth, fliersize, plot_kws)
633 data = pd.DataFrame({self.orient: positions, "width": orig_width})
634 if dodge:
--> 635 self._dodge(sub_vars, data)
636 if gap:
637 data["width"] *= 1 - gap
File ~/code/seaborn/seaborn/categorical.py:391, in _CategoricalPlotter._dodge(self, keys, data)
389 def _dodge(self, keys, data):
390 """Apply a dodge transform to coordinates in place."""
--> 391 hue_idx = self._hue_map.levels.index(keys["hue"])
392 n = len(self._hue_map.levels)
393 data["width"] /= n
AttributeError: 'NoneType' object has no attribute 'index' Which looks similar (if not identical) to the reported traceback. However as noted, |
This issue is seen in
|
The dodge operation is undefined when you haven’t assigned a hue variable. There should probably be a fix to handle this more gracefully, but the existing bug is not preventing you from doing anything. |
What I meant was, Can I submit a pull request to resolve this issue? |
Hello,
I want to report a bug when using the latest version of Seaborn. I checked with 0.12.2 there was no error.The bug is:
File "/mnt/c/Users//Desktop/Gent_presentation_2023/1_Effect_of_Ti_addition/2-formation_energy/all_Tix_analysis/./boxplot.py", line 287, in
statplot_cols()
File "/mnt/c/Users//Desktop/Gent_presentation_2023/1_Effect_of_Ti_addition/2-formation_energy/all_Tix_analysis/./boxplot.py", line 59, in statplot_cols
pp = sns.boxplot(
File "/home//miniconda3/lib/python3.10/site-packages/seaborn/categorical.py", line 1619, in boxplot
p.plot_boxes(
File "/home//miniconda3/lib/python3.10/site-packages/seaborn/categorical.py", line 637, in plot_boxes
self._dodge(sub_vars, data)
File "/home/*****/miniconda3/lib/python3.10/site-packages/seaborn/categorical.py", line 391, in _dodge
hue_idx = self._hue_map.levels.index(keys["hue"])
KeyError: 'hue'
Can you check why is that?
The text was updated successfully, but these errors were encountered: