Skip to content

Can't use col_wrap with seaborn.relplot #18

@harper357

Description

@harper357

I have a relplot with the parameter col_wrap, but it gives me the following error:

File ~/.pyenv/versions/3.9.6/envs/venv3.9.6/lib/python3.9/site-packages/seaborn/_decorators.py:46, in _deprecate_positional_args.<locals>.inner_f(*args, **kwargs)
     36     warnings.warn(
     37         "Pass the following variable{} as {}keyword arg{}: {}. "
     38         "From version 0.12, the only valid positional argument "
   (...)
     43         FutureWarning
     44     )
     45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)

File ~/.pyenv/versions/3.9.6/envs/venv3.9.6/lib/python3.9/site-packages/seaborn/relational.py:1027, in relplot(x, y, hue, size, style, data, row, col, col_wrap, row_order, col_order, palette, hue_order, hue_norm, sizes, size_order, size_norm, markers, dashes, style_order, legend, kind, height, aspect, facet_kws, units, **kwargs)
   1025 # Set up the FacetGrid object
   1026 facet_kws = {} if facet_kws is None else facet_kws.copy()
-> 1027 g = FacetGrid(
   1028     data=full_data.dropna(axis=1, how="all"),
   1029     **grid_kws,
   1030     col_wrap=col_wrap, row_order=row_order, col_order=col_order,
   1031     height=height, aspect=aspect, dropna=False,
   1032     **facet_kws
   1033 )
   1035 # Draw the plot
   1036 g.map_dataframe(func, **plot_kws)

File ~/.pyenv/versions/3.9.6/envs/venv3.9.6/lib/python3.9/site-packages/patchworklib/modified_grid.py:219, in __init_for_facetgrid__(self, data, row, col, hue, col_wrap, sharex, sharey, height, aspect, palette, row_order, col_order, hue_order, hue_kws, dropna, legend_out, despine, margin_titles, xlim, ylim, subplot_kws, gridspec_kws, size, pyplot)
    216 if despine:
    217     #self.despine()
    218     for axs in axes:
--> 219         for ax in axs:
    220             ax.spines["right"].set_visible(False)   
    221             ax.spines["left"].set_visible(True) 

TypeError: 'AxesSubplot' object is not iterable

My plot works if I delete col_wrap, but puts obviously puts all the subplots on the same row. Is there a reason you have

for axs in axes:
for ax in axs:
as nested for loops instead of using axes.flatten()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions