0% found this document useful (0 votes)
46 views

Chapter 3

The document discusses different types of categorical plots that can be created with Seaborn, including plots that show each observation, abstract representations like boxplots and violin plots, and statistical estimates like bar plots and count plots. It provides examples of using Seaborn functions like stripplot, swarmplot, boxplot, violinplot, barplot, and countplot to create these different types of categorical plots.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Chapter 3

The document discusses different types of categorical plots that can be created with Seaborn, including plots that show each observation, abstract representations like boxplots and violin plots, and statistical estimates like bar plots and count plots. It provides examples of using Seaborn functions like stripplot, swarmplot, boxplot, violinplot, barplot, and countplot to create these different types of categorical plots.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Categorical Plot

Types
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N

Chris Mo
Instructor
Categorical Data
Data which takes on a limited and xed number of values

Normally combined with numeric data

Examples include:
Geography (country, state, region)

Gender

Ethnicity

Blood type

Eye color

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plot types - show each observation

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plot types - abstract representations

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plot types - statistical estimates

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plots of each observation - stripplot
sns.stripplot(data=df, y="DRG Definition",
x="Average Covered Charges",
jitter=True)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plots of each observation - swarmplot
sns.swarmplot(data=df, y="DRG Definition",
x="Average Covered Charges")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Abstract representations - boxplot
sns.boxplot(data=df, y="DRG Definition",
x="Average Covered Charges")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Abstract representation - violinplot
sns.violinplot(data=df, y="DRG Definition",
x="Average Covered Charges")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Abstract representation - lvplot
sns.lvplot(data=df, y="DRG Definition",
x="Average Covered Charges")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Statistical estimates - barplot
sns.barplot(data=df, y="DRG Definition",
x="Average Covered Charges",
hue="Region")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Statistical estimates - pointplot
sns.pointplot(data=df, y="DRG Definition",
x="Average Covered Charges",
hue="Region")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Statistical estimates - countplot
sns.countplot(data=df, y="DRG_Code", hue="Region")

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Let's practice!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Regression Plots
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N

Chris Mo
Instructor
Bicycle Dataset
Aggregated bicycle sharing data in Washington DC

Data includes:
Rental amounts

Weather information

Calendar information

Can we predict rental amounts?

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plotting with regplot()
sns.regplot(data=df, x='temp',
y='total_rentals', marker='+')

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Evaluating regression with residplot()
A residual plot is useful for evaluating the t of a model

Seaborn supports through residplot function

sns.residplot(data=df, x='temp', y='total_rentals')

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Polynomial regression
Seaborn supports polynomial regression using the order
parameter

sns.regplot(data=df, x='temp',
y='total_rentals', order=2)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


residplot with polynomial regression
sns.residplot(data=df, x='temp',
y='total_rentals', order=2)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Categorical values
sns.regplot(data=df, x='mnth', y='total_rentals',
x_jitter=.1, order=2)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Estimators
In some cases, an x_estimator can be useful for highlighting
trends

sns.regplot(data=df, x='mnth', y='total_rentals',


x_estimator=np.mean, order=2)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Binning the data
x_bins can be used to divide the data into discrete bins

The regression line is still t against all the data

sns.regplot(data=df,x='temp',y='total_rentals',
x_bins=4)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Let's practice!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Matrix Plots
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N

Chris Mo
Instructor
Getting data in the right format
Seaborn's heatmap() function requires data to be in a grid
format

pandas crosstab() is frequently used to manipulate the


data

pd.crosstab(df["mnth"], df["weekday"],
values=df["total_rentals"],aggfunc='mean').round(0)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Build a heatmap
sns.heatmap(pd.crosstab(df["mnth"], df["weekday"],
values=df["total_rentals"], aggfunc='mean')
)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Customize a heatmap
sns.heatmap(df_crosstab, annot=True, fmt="d",
cmap="YlGnBu", cbar=False, linewidths=.5)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Centering a heatmap
Seaborn support centering the heatmap colors on a speci c
value

sns.heatmap(df_crosstab, annot=True, fmt="d",


cmap="YlGnBu", cbar=True,
center=df_crosstab.loc[9, 6])

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Plotting a correlation matrix
Pandas corr function calculates correlations between
columns in a dataframe

The output can be converted to a heatmap with seaborn

sns.heatmap(df.corr())

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Let's practice!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N

You might also like