Skip to content
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

Error with dodge kwarg when using FacetGrid together with pointplot #3658

Open
chris-n-self opened this issue Mar 18, 2024 · 2 comments
Open

Comments

@chris-n-self
Copy link

This seems to be the same issue as this but in a different circumstance: #3553

If do the following:

g = sns.FacetGrid(
    df,
    col="col_field",
    hue="hue_field",
)
g.map(
    sns.pointplot,
    'x_field',
    'y_field',
    estimator='mean',
    errorbar='sd',
    linestyles='none',
    markers='x',
    dodge=0.1,
)

I get this error:

File ~/miniconda3/envs/my_env/lib/python3.10/site-packages/seaborn/categorical.py:1217, in _CategoricalPlotter.plot_points(self, aggregator, markers, linestyles, dodge, color, capsize, err_kws, plot_kws)
   1208 agg_data = sub_data if sub_data.empty else (
   1209     sub_data
   1210     .groupby(self.orient)
   (...)
   1213     .reset_index()
   1214 )
   1216 if dodge:
-> 1217     hue_idx = self._hue_map.levels.index(sub_vars["hue"])
   1218     step_size = dodge / (n_hue_levels - 1)
   1219     offset = -dodge / 2 + step_size * hue_idx

AttributeError: 'NoneType' object has no attribute 'index'

If I set dodge=True instead of a value I do not get an error but the dodge is not applied

@thuiop
Copy link
Contributor

thuiop commented Mar 19, 2024

Please provide a reproducible example. But I bet the issue is that you are passing the hue argument to the FacetGrid instead of inside map.

@mwaskom
Copy link
Owner

mwaskom commented Mar 19, 2024

Yes — this wouldn't work anyway, even if it gave a better error message. I think you want to use catplot here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants