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