python seaborn plot(sns)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python seaborn plot(sns)相关的知识,希望对你有一定的参考价值。

import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="whitegrid", color_codes=True)
sns.set(font_scale=1)

# Collect Figure
g = sns.FUNCTION_PLOT() # for example: sns.heatmap()
fig = g.fig

# Set Title
plt.subplots_adjust(top=0.90)
g.fig.suptitle('THIS IS A TITLE, YOU BET',fontsize=16)



## HEAT MAP - Correlation

# data (df)
corr=DATA[['var1','var2','var3','var4','var5','var6']].corr()
# plot
sns.heatmap(corr,vmin=0.,vmax=1., square=True, annot=True, linewidths=.5, cmap='jet')
plt.title('Correlation between variables')
plt.show()


## SCATTER + HISTOGRAMS (x, y)
sns.jointplot(x,y,color='gold',size=10, kind="reg"))
plt.show()

## SCATTER (x,y) where x is categorical
sns.stripplot(x=datax, y=datay,jitter=True)
plt.show()

## Histogram with fitted line
sns.distplot(data)
plt.show()

## PLOT of variables (x,y) for several categorical variable z
sns.factorplot("varx","vary",data=DF,hue="varz")
plt.show()

## BOXPLOT
sns.boxplot(data,color='r')
plt.show()
## GROUPED BOXPLOT
sns.boxplot(x='colx', y='coly', data=df)
    
## BARPLOT with std bar error
sns.barplot(x,y)
plt.show()

## COUNT categorical observations and display by BARplotS
sns.countplot(x = 'var cat x', data = DF)
plt.show()

## PLOT per any label in different charts
g = sns.FacetGrid(DF, col="per_this_column",col_wrap=2,size = 5,xlim=(0,70),ylim=(0.,12.))
g = g.map(plt.bar, "column_x", "column_y", edgecolor="w") ## BAR CHART
g = g.map(plt.scatter, "column_x", "column_y", edgecolor="w") ## SCATTER PLOT

## BAR CHART OF COUNT categorical values of any variable
sns.countplot(x='cat_var',data=df, palette='hls')


## close figure
sns.reset_orig()

以上是关于python seaborn plot(sns)的主要内容,如果未能解决你的问题,请参考以下文章

plotly.express - 像 sns.lineplot 中的置信区间

Matplotlib学习---用seaborn画矩阵图(pair plot)

python 绘制多个图表 - Seaborn(sns)

seaborn plot 小提琴的阵列

停止 seaborn 在彼此之上绘制多个图形

Plotly Express 热图无法正常工作