Can't use catplot with melt for different categories
See original GitHub issueI would have expected that I can visualize different categorical variables in a count plot using catplot
and melt
.
However, it looks like the data is converted to categorical before grouping for the columns, and so the categories are shared among all the count plots. That doesn’t really make sense if the different columns correspond to different categories.
Am I overlooking something or is there a different way of doing this?
import pandas as pd
import seaborn as sns
ames = pd.read_excel("http://www.amstat.org/publications/jse/v19n3/decock/AmesHousing.xls")
cat_cols = ['MS Zoning', 'Street', 'Alley', 'Lot Shape', 'Land Contour',
'Utilities', 'Lot Config', 'Land Slope', 'Neighborhood', 'Condition 1',
'Condition 2', 'Bldg Type', 'House Style', 'Roof Style', 'Roof Matl',
'Exterior 1st', 'Exterior 2nd', 'Mas Vnr Type', 'Exter Qual',
'Exter Cond', 'Foundation', 'Bsmt Qual', 'Bsmt Cond', 'Bsmt Exposure',
'BsmtFin Type 1', 'BsmtFin Type 2', 'Heating', 'Heating QC',
'Central Air', 'Electrical', 'Kitchen Qual', 'Functional',
'Fireplace Qu', 'Garage Type', 'Garage Finish', 'Garage Qual',
'Garage Cond', 'Paved Drive', 'Pool QC', 'Fence', 'Misc Feature',
'Sale Type', 'Sale Condition']
ames_cat = ames[cat_cols]
sns.catplot(x='value', col='variable', data=ames_cat.melt(), sharex=False, sharey=False, col_wrap=5, kind='count')
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Is there a restriction on catplot with subplot? - Stack Overflow
Catplot is a figure-level function whereas you cannot use axes. Try using stripplot instead. fig, axs = plt.subplots (1, 2, figsize=(25, ...
Read more >seaborn.catplot — seaborn 0.12.1 documentation - PyData |
This function provides access to several axes-level functions that show the relationship between a numerical and one or more categorical variables using one ......
Read more >Three common seaborn difficulties | by Michael Waskom
This post aims to explain three of the most common difficulties encountered by users of seaborn, a Python library for data visualization.
Read more >Mastering catplot() in Seaborn with categorical plots
Fortunately, a data visualization library Seaborn encompasses several types of categorical plots into a single function: catplot() .
Read more >New Plot Types in Seaborn's Latest Release
Seaborn release 0.9 contains several new plot types as well as other ... In practice, Seaborn works best when using Pandas dataframes and ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Indeed,
catplot
has some logic that unifies categories across the facets, becausesharex
(which just gets passed down tosubplots
) won’t do it on its own. But it doesn’t not do that if the user specifiessharex=False
.(Notes to myself: this is a bit tricky because it will have to figure out from the
_CategoricalPlotter
which way the plot is oriented, i.e. it’s not as simple as depending onsharex
).Anyway you can use
FacetGrid
directly, which usually is risky because the categorical axis won’t be shared, but that’s what you want here:(If I understand what you’re aiming for, this should do it).
It does! someone should collect all your issue replies and make a seaborn cook-book. Thank you for your quick and insightful reply!.
I’m not sure if I understand your explanation as I’m using
sharex=False
and I still observe the behavior. But I have the solution I was looking for!