首页 > 编程语言 >python3使用matplotlib和seaborn生成带有扰动点的箱型图

python3使用matplotlib和seaborn生成带有扰动点的箱型图

时间:2022-12-02 16:25:49浏览次数:41  
标签:plt jitter seaborn df matplotlib sns reader 箱型

import csv
import seaborn as sns
import matplotlib.pyplot as plt

# 解决中文不显示和负号不显示问题
rc = {
    'font.family': 'Microsoft YaHei', 'axes.unicode_minus': False
}
fig = plt.figure(figsize=(20, 5))
sns.set(style="darkgrid", rc=rc)

# ------------------------------------------------------------------------------------------------------
# 实例程序 加载示例数据集
# df = sns.load_dataset('iris',data_home="E:\code\learn-python3\seaborn-data-master")
# df.head()
# ax = sns.boxplot(x='species', y='sepal_length', data=df)
# ax = sns.stripplot(x='species', y='sepal_length', data=df, color="orange", jitter=0.2, size=4)
# plt.title("Boxplot with jitter", loc="center")
# plt.show()

# ------------------------------------------------------------------------------------------------------
# 读取csv文件获取原始数据并处理数据
xData = []
yData = []
num = 2
with open('./files/test.csv', encoding='utf-8-sig') as f:
    reader = csv.reader(f, skipinitialspace=True)
    headers = next(reader)
    for row in reader:
        for i in range(0, num, 1):
            if (len(row) == 12):
                xData.append(headers[6+i*2])
                yData.append(float(row[6+i*2]))

# boxplot
ax = sns.boxplot(x=xData, y=yData)
# 添加扰动点
ax = sns.stripplot(x=xData, y=yData, color="orange", jitter=0.2, size=4)

plt.xlabel('code')
plt.ylabel('value')
plt.title("Boxplot with jitter", loc="center")
# plt.show()
plt.savefig('./files/1.jpg')

 

标签:plt,jitter,seaborn,df,matplotlib,sns,reader,箱型
From: https://www.cnblogs.com/caroline2016/p/16944783.html

相关文章

  • matplotlib绘图
    matplotlib绘图importmatplotlib.pyplotaspltimportnumpyasnp plt.plot()绘制线性图绘制单条线形图绘制多条线形图设置坐标系的比例plt.figure(figs......
  • Matplotlib 可视化50图:散点图(1)
    导读本系列将持续更新50个matplotlib可视化示例,主要参考SelvaPrabhakaran在MachineLearningPlus上发布的博文:Python可视化50图。定义关联图是查看两个事物之间关系的......
  • MacOS|matplotlib 无法显示中文 解决办法
    matplotlib无法显示中文解决办法画图时,中文无法正常显示,如图下载字体点击这里获取字体提取码:wnby查看字体路径在python环境中执行以下指令importmatplotlib......
  • 68-72.图标的作用,初识matplotlib,简单绘图
            -------------------------------------------------------------------------------------------------------------------------------------......
  • Matplotlib基础教程之折线图
    1.数据可视化的意义俗话说,一图胜千言。数据可视化便是将数据通过图形化的方式展现出来,它更加便于我们观察数据蕴含的的规律,洞察了数据蕴含的规律后,我们能够做更好的商业决......
  • matplotlib 字体
    linux平台matplotlib字体报错如下:Fontfamily['TimesNewRoman']notfound.解决步骤:step1condainstall-cconda-forge-ymscorefontsstep2importm......
  • Matplotlib数据可视化——次坐标
    何谓次坐标,即共享一个x轴,左右两个y轴。左边为主,右侧为次importmatplotlib.pyplotaspltimportnumpyasnp#构造两个函数x=np.arange(0,10,0.2)y1=0.27*x**2......
  • Matplotlib数据可视化——subplot的另外三种常用方法
    第一种方法:subplot2grid定义一个3*3的矩阵位置,利用subplot2grid分别框选出想要的区域大小,进而在区域中plot出想绘制的函数即可,colspan与rowspan分别表示行数和列数,用来界......
  • Matplotlib数据可视化——图中图
    importmatplotlib.pyplotasplt"""图中图实验"""#绘制大图fig=plt.figure()#使用figure后往往在函数前要加set_或add_等前缀x=[1,2,3,4,5,6,7]y=[1,3......
  • Matplotlib数据可视化——显示图片【对比OpenCV显示图片】
    第一个是自己建立了一个矩阵当做图片显示,代码和图片如下:A=[0.3136,0.3654,0.4237, 0.3653,0.4396,0.5251, 0.4237,0.5251,0.6515]image=np.array(A).resh......