“”“绘制直方图plt”""
for i in range(len(data.columns)):
plt.hist(data[data.columns[i]].get_values())
plt.xlabel(data.columns[i])
plt.show()
“”“绘制唯一值的条形图”""
column_list = data.columns.tolist()
for column in column_list:
a= data[column].value_counts().tolist()
b = data[column].unique()
plt.figure()
plt.bar(x=b,height=a)
plt.tight_layout()
plt.show()
饼图的相应参数设置:
matplotlib.pyplot.pie(x,explode,labels,autopct,shadow,startangle,...)
explode:设置爆炸区域,列表形式传入参数
autopct:自定义饼图的百分比属性,"%.02f%%"
shadow:是否有阴影,默认无
startangle:自定义第一块饼图与水平面的角度
counterclock:按逆时针对饼图进行排列
查看房屋的值得个数得饼图可视化
高级饼图绘图函数封装
def explode_situtation(data): # 此处的data传入的是一个value_counts()参数
explode = {}
for i in range(len(data)):
if data[i]>data.mean():
explode[data.index[i]] = 0.1
else:
explode[data.index[i]] = 0
return explode
explode = list(explode_situtation(listing["neighbourhood"].value_counts()).values())
value = listing["neighbourhood"].value_counts()
label = listing["neighbourhood"].unique().tolist()
plt.figure(figsize=(10,10),dpi=80)
plt.title("民俗区域分布权重图")
plt.pie(value,labels=label,autopct="%.2f%%",explode=explode,startangle=90,counterclock=False)
plt.legend(loc="best",shodow=True,fontsize=11)
图形位置摆放的seabron的盒型图
subsets = ["col1","col2","col3"]
fig,axes = plt.subplots(len(subsets),1,figsize=(10,10))
plt.subplots_adjust(hspace=1)
for i,subset in enumerate(subsets):
sns.boxplot(df[subset],ax=axes[i],whis=2,orient="h")
“”"
参数orient:“r”|“h"控制图像的显示方向
参数whis:确定离群值的上下界
“””
“”"
sns.heatmap热力图的用法
data.corr()
参数annot:默认为False,为True的时候在格子上显示数字
Vmax,Vmin:颜色取值的最大、最下值,默认为从data中你推导
cmap:matplotlib的colormap名称或者颜色对象,默认为cubehelix_map(连续数据集时)或者用RdBu_r(离散数据集时可用)
“”"
plt.figure(figsize=(10,10))
sns.set(font_scale=1.5)
sns.heatmap(df.corr(),annot=True,Vmin=-1,Vmax=1,cmap=sns.color_palette("hls",n_colors=8))
plt.show()
“”"
利用pd.pivot_table透视图结合sns.heatmap进行使用
参数fill_value:将nan设置为0,
参数margins=True,可以汇总行列数据
“”"
热力图的设置结合透视图
pd.options.display.precision = 2
feature_df = pd.pivot_table(df,index="neighbourhood",values=["price","reviews"],columns="room_type",aggfuc=np.mean)
sns.heatmap(feature_df.price,camp=sns.color_palette("RdBur_r",n_colors=32),annot=True)
散点图scatter
plt.scatter(x,y,color,alpha)
“”"
scatter中传入参数:color控制颜色,以及alpha参数,散点的透明度
利用散点图scatter对数据进行分颜色显示可视化的骚操作
colors= [“red”,“green”,“blue”,“yellow”]
plt.scatter(data[“col1”],data[“col2”],c=colors[data[“cluster”]])
还可以添加参数:linewidths,marker,s,c
“”"
crosstab交叉表
fig,ax = plt.subplots(figsize=(10,10))
sns.heatmap(pd.crosstab(data["col1"],data["col2"]),cmap="Blues",annot=True,fmt="d",ax=ax)
ax.set_title()
fig.tight_layout()
“”" missing库的可视化操作