Python 画 箱线图
flyfish
箱线图 其他名字 盒须图 / 箱形图
横向用正态分布看
垂直看
pandas画
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 画好看点
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. 刻凹痕 / 完成 / 获得 / 赢得