python数据分析之云雨图(箱型图+分布图+散点图)
图效果
代码实现
1、导入包
import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import ptitprince as pt
2、读取.csv文件
df=pd.read_csv(D:/driver/Analysis/jiangwei.csv)#读取csv文件 df1=df[df.carId<=2235] #取数据
df数据 3、绘制云雨图
dy="carId" dx="speed" ort="h" pal="Set2" f, ax=plt.subplots(figsize=(7, 5)) ax=pt.half_violinplot(x=dx, y=dy, data=df1, palette=pal, bw=.2, cut=0., scale="area", width=.6, inner=None, orient=ort) ax=sns.stripplot(x=dx, y=dy, data=df1, palette=pal, edgecolor="white", size=3, jitter=1, zorder=0, orient=ort, ) ax=sns.boxplot(x=dx, y=dy, data=df1, color="black", width=.15, zorder=10, showcaps=True, boxprops={ facecolor:none,"zorder":10}, showfliers=True, whiskerprops={ linewidth:2,"zorder":10}, saturation=1, orient=ort) plt.title("Raincloud") plt.show()
全部代码
import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import ptitprince as pt df=pd.read_csv(D:/driver/Analysis/jiangwei.csv)#读取csv文件 df1=df[df.carId<=2235] #取数据 dy="carId" dx="speed" ort="h" pal="Set2" f, ax=plt.subplots(figsize=(7, 5)) ax=pt.half_violinplot(x=dx, y=dy, data=df1, palette=pal, bw=.2, cut=0., scale="area", width=.6, inner=None, orient=ort) ax=sns.stripplot(x=dx, y=dy, data=df1, palette=pal, edgecolor="white", size=3, jitter=1, zorder=0, orient=ort, ) ax=sns.boxplot(x=dx, y=dy, data=df1, color="black", width=.15, zorder=10, showcaps=True, boxprops={ facecolor:none,"zorder":10}, showfliers=True, whiskerprops={ linewidth:2,"zorder":10}, saturation=1, orient=ort) plt.title("Raincloud") plt.show()