- df.column.plot(kind=” ”)
- ‘bar’ or ‘barh’ for bar plots ; ‘hist’ for histogram
- ‘box’ for boxplot ; ‘kde’ or ‘density’ for density plots
- ‘area’ for area plots; ‘scatter’ for scatter plots
- ‘hexbin’ for hexagonal bin plots ;‘pie’ for pie plots
2. df.price.hist(bins=10,by=df.room_type)
劃出不同room_type 的價格分布圖
3. df[[“column1”,”column2"]].dropna().plot()
可以將兩個columns 畫一起
seaborn as sns
- sns.barplot(data=df,x=”price”,y=”room_type”)
根據room type 展現 average price
2. sns.barplot(data=df.loc[df.minimum_nights<7],y=”price”,hue=”room_type”,x=”minimum_nights”)
根據minimum_nights 及不同的 room_type 展現avg price
- seaborn.distplot — similar to histogram
Gaussian Kernel Density Estimate
sns.distplot(data,hist=False,rug=True,kde_kws={“shade”:True}
2. sns.kdeplot(data, bw=10,shade=Ture)
bw=binwidth
3. sns.regplot(X=”column1",Y=”column2",hue=”column3",data=df)
regplot function generate a scatterplot with a regression line
4. sns.lmplot(X=”column1",Y=”column2",data=df,col=”column3"))
5. sns.lvplotsns.lvplot(data=df, x=’Award_Amount’,y=’Model Selected’,palette=’Paired’,hue=’Region’)
sns.residplot(data=df,x=”column1",y=”column2",order=2)
order — turn it to polynomial (residual should be normally distributed)
對稱分配則表示兩個variables 有linear relations
x_estimator — to highlight the trend
sns.regplot(data=df,x=”mnth”,y=”total_rentals”,x_estimator=np.mean,order=2)
6. sns.heatmap 可以與pd.crosstab 連用
sns.heatmap(pd.crosstab(df[“column1”],df[“column2”],value=df[“column3”],aggfunc=mean),annot=True,cmap=”YlGnBu”)
7. FacetGrid, factorplot, lmplot
sns.factorplot(data=df,x=”column1”,col=”column2",kind=”box”)
lmplot-plot regression and scatter plot on facetgrid
sns.lmplot(data=df,x=”column1”,y=”column4",col=”column2",row=”column3",fit_reg=True)
FacetGrid
g=sns.FacetGrid(data=df, row=”column1”)
g.map(sns.pointplot, “column2”)
8. sns.pairplot(data=df,vars=[“fatal_collisions”, “premiums”],kind=’scatter’)
5. Matplotlib Axes (customized your plots)
fig,(ax0,ax1)=plt.subplots(nrows=1,ncols=2,sharey=True 共享y軸,figsize=(7,4))
sns.distplot(df[“column1”],ax=ax0)
ax0.set(xlabel=”column name”,xlim=(0,1000),title=”title name”)
ax0.axvline(x=20000,label=”budget”,linestyle=”-”)
ax0.legend()
plotly.express 做圖
- import plotly.express as px
fig=px.scatter(df,x=”price”,y=”number_of_reviews”)
fig.show()