Python 画 箱线图

Python 画 箱线图

flyfish

箱线图 其他名字 盒须图 / 箱形图

横向用正态分布看

垂直看

pandas画

py 复制代码
import pandas as pd

import seaborn as sns  
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('sh300.csv')
print("原始数据")
print(df.head(3))
df = df[['high']]
#plt.boxplot(df,vert=False)#水平
plt.boxplot(df,vert=True,showbox=True,showcaps=True,showfliers=True,showmeans=True)#垂直
plt.show()

matplotlib 画好看点

py 复制代码
import matplotlib.pyplot as plt
import numpy as np

# Random test data
np.random.seed(1)
all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)]
labels = ['x1', 'x2', 'x3']

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(9, 4))

# rectangular box plot
bplot1 = ax1.boxplot(all_data,
                     vert=True,  # vertical box alignment
                     patch_artist=True,  # fill with color
                     labels=labels)  # will be used to label x-ticks
ax1.set_title('Rectangular box plot')

# notch shape box plot
bplot2 = ax2.boxplot(all_data,
                     notch=True,  # notch shape
                     vert=True,  # vertical box alignment
                     patch_artist=True,  # fill with color
                     labels=labels)  # will be used to label x-ticks
ax2.set_title('Notched box plot')

# fill with colors
colors = ['sandybrown', 'olivedrab', 'steelblue']
for bplot in (bplot1, bplot2):
    for patch, color in zip(bplot['boxes'], colors):
        patch.set_facecolor(color)

# adding horizontal grid lines
for ax in [ax1, ax2]:
    ax.yaxis.grid(True)
    ax.set_xlabel('Three separate samples')
    ax.set_ylabel('Observed values')

plt.show()
box plot
n. <统计>箱形图
亦作 box-and-whisker plot)
box-and-whisker plot
box-and-whisker diagram
n. 盒须图 / 箱线图 / 同 box plot

whisker
['wɪskər] 
['wɪskə] 
n. 须 / 髯 / 晶须 / 胡须

plot
[plɑːt] 
[plɒt] 
n. 阴谋 / 情节 / 小块地 / 图表
v. 密谋 / 计划 / 设计情节 / 标记
现在分词: plotting
过去式: plotted

notch
美[nɑːtʃ] 
英[nɒtʃ] 
n. 槽口 / 凹痕 / <北美>山路 / 等级

v. 刻凹痕 / 完成 / 获得 / 赢得
相关推荐
大数据追光猿5 分钟前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
Leuanghing29 分钟前
【Leetcode】11. 盛最多水的容器
python·算法·leetcode
xinxiyinhe2 小时前
如何设置Cursor中.cursorrules文件
人工智能·python
诸神缄默不语2 小时前
如何用Python 3自动打开exe程序
python·os·subprocess·python 3
橘子师兄2 小时前
分页功能组件开发
数据库·python·django
Logintern093 小时前
使用VS Code进行Python编程的一些快捷方式
开发语言·python
Multiple-ji3 小时前
想学python进来看看把
开发语言·python
liuyuzhongcc4 小时前
List 接口中的 sort 和 forEach 方法
java·数据结构·python·list
鸟哥大大4 小时前
【Python】pypinyin-汉字拼音转换工具
python·自然语言处理
jiugie4 小时前
MongoDB学习
数据库·python·mongodb