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. 刻凹痕 / 完成 / 获得 / 赢得
相关推荐
shirsl2 小时前
算法 Day1-数组 / 哈希 + 双指针
python·算法·哈希算法
广州山泉婚姻8 小时前
Python序列号源码分析
python
计算机源码社8 小时前
【大数据项目实战】基于大数据的影视内容生态综合质量分析与可视化-基于数据挖掘的影视内容类型共现与口碑聚类分析系统
大数据·人工智能·python·数据挖掘·数据分析·毕业设计·课程设计
C^h8 小时前
pytorch 适合初学者 0基础学习
人工智能·pytorch·python
小柯南敲键盘9 小时前
跨马翻译:AI批量图片翻译工具,跨境电商视频字幕翻译与智能抠图一体搞定
人工智能·python·音视频
2601_962297259 小时前
Python里behave和pytest-bdd哪个更适合中大型项目?为什么?
python·bdd·行为驱动开发·behave·pytest-bdd
YCOSA202511 小时前
系统工具使用检测.exe (仅供娱乐)
python·microsoft
2601_9622953311 小时前
如何python实现网页的自动化
python·selenium·beautifulsoup·requests·网页自动化
ofoxcoding11 小时前
GPT Image 2.5 API 实战:Python 调用实现图片生成与编辑
人工智能·python·gpt·ai
张小姐的猫12 小时前
【AI大模型接入SDK】 —— Gemini接入封装
android·数据结构·数据库·c++·人工智能·python