Home  >  Article  >  Backend Development  >  [Python Tutorial] Drawing a Violin Plot

[Python Tutorial] Drawing a Violin Plot

黄舟
黄舟Original
2017-02-07 16:13:047112browse

小提琴图(Violinplot)可以理解为箱图(Boxplot)加上密度图(Kdensity),本文简单介绍在Python中如何绘制该图,使用数据为Stata软件系统自带auto数据(已导出为CSV格式)。

导入命令

1)设置工作环境
%cd "F:\\Dropbox\\python"2)导入程序包import pandas as pd
import seaborn as sns
3)读取数据tips=pd.read_csv("stata_auto.csv")
4)定义并绘制图像
sns.set(style="whitegrid",palette="pastel",color_codes=ture)
sns.violinplot(x="rep78", y="mpg", data=tips, split=True,inner="quart")
sns.despine(left=True)

输出图像如下

[Python Tutorial] Drawing a Violin Plot

以上就是【Python教程】绘制小提琴图的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn