**from** *matplotlib* **import** *pyplot* **as** *plt*
**import** *seaborn* **as** *sns*
**import** *numpy* **as** *np*
**sns.barplot**(
**data**=df ,
**x**=*"x value column"* ,
**y**=*"y value column"*,
*# everything specified below is optional*
**ci**=*"sd"*
**estimator**=*np.median* | *len*
**hue**=*"column to compare"*
)
plt.show()
# **ci**=*"sd"* changes the **error bar** to *standard deviation*
# **estimator** is used to specifiy the **aggregation** and takes any argument that **works on a list**. *(examples provided in code)*
# **hue** adds a nested categorical variable to compare to the *"y value column"*
|
Median
|
np.median(df.column_name)
|
|
sns.kdeplot(dataset1, shade=True)
|
|
sns.kdeplot(dataset2, shade=True)
|
|
...
|
**sns.boxplot**(
data=df,
x='label',
y='value',
*# optional*
width=0.45
)
plt.show()
**# In Seaborn it's also possible to plot multiple Boxplots in one viz**
sns.violinplot(
data=df,
x="label",
y="value"
)
# *Themes: (called prior to plot)*
**sns.set_style**("")
->*darkgrid, whitegrid, dark, white, ticks*
#*Removes Plot Borders (called after plot)*
**sns.despine**() *(default: top=True, right=True)*
-> *bottom, left*
#*Adjust font- and label size*
**sns.set_context**(**context**="paper", **font_scale**=1.4, **rc**={"grid.linewidth": 0.6} )
-> *paper, notebook (default), talk, poster*
*In order of relative size*
-> *Arguments for **rc** parameter:*
{
'axes.labelsize': 17.6,
'axes.titlesize': 19.0,
'font.size': 19.2,
'grid.linewidth': 1.6,
'legend.fontsize': 16.0,
'lines.linewidth': 2.8,
'lines.markeredgewidth': 0.0,
'lines.markersize': 11.2,
'patch.linewidth': 0.48,
'xtick.labelsize': 16.0,
'xtick.major.pad': 11.2,
'xtick.major.width': 1.6,
'xtick.minor.width': 0.8,
'ytick.labelsize': 16.0,
'ytick.major.pad': 11.2,
'ytick.major.width': 1.6,
'ytick.minor.width': 0.8
}
# **If you want to quickly see what a palette looks like**
# *Save a palette to a variable:*
palette = **sns.color_palette**("bright")
# *Use palplot and pass in the variable:*
**sns.palplot**(palette)
# **Select a palette in Seaborn:**
**sns.set_palette**("Paired")
# **Default Palettes**
-> *deep, muted, pastel, bright, dark, colorblind*
# **More Palettes using Color Brewer:**
http://colorbrewer2.org
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.