pansas 绘制定制的箱线图

 1  普通风格

代码

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = 'SimHei'   # 使图形中的中文正常编码显示
plt.rcParams['axes.unicode_minus'] = False   # 使坐标轴刻度表签正常显示正负号

rng = np.random.RandomState(27)
x = rng.normal(loc=0, scale=1.5, size=9000)

df = pd.DataFrame([x, x+1.5]).T
df.columns=['甲', '乙']

df.plot(kind='box')

plt.show()

图形

 

2、定制风格

代码

# -*- coding: utf-8 -*-
"""
Created on Sun Dec  1 13:53:53 2019

@author: Mr.Su
"""


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = 'SimHei'   # 使图形中的中文正常编码显示
plt.rcParams['axes.unicode_minus'] = False   # 使坐标轴刻度表签正常显示正负号

# 生成数据
rng = np.random.RandomState(27)
x = rng.normal(loc=0, scale=1.5, size=9000)

# 创建数框
df = pd.DataFrame([x, x+1.5]).T
df.columns=['', '']

# 设置图形属性
fig = plt.figure('赏尔', facecolor='tan')
ax = plt.gca()

colors = dict(boxes='darkgreen', whiskers='darkorange',
              medians='red', caps='red')
df.plot(ax=ax, kind='box', color=colors, grid=True)

plt.show()

图形

 

3 定制风格 2

代码

# -*- coding: utf-8 -*-
"""
Created on Sun Dec  1 13:53:53 2019

@author: Mr.Su
"""


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = 'SimHei'   # 使图形中的中文正常编码显示
plt.rcParams['axes.unicode_minus'] = False   # 使坐标轴刻度表签正常显示正负号

# 生成数据
rng = np.random.RandomState(27)
x = rng.normal(loc=0, scale=1.5, size=9000)

# 创建数框
df = pd.DataFrame([x, x+1.5]).T
df.columns=['', '']

# 设置图形属性
fig = plt.figure('赏尔', facecolor='tan')
ax = plt.gca()

colors = dict(boxes='darkgreen', whiskers='darkorange',
              medians='red', caps='red')
df.plot(ax=ax, kind='box', color=colors, grid=True,
        sym='*',         # 异常值形状
        vert = False,    # 是否垂直 
        notch = True)    # 显示缺口

plt.show()

图形

 

 

。。。

posted @ 2018-12-06 23:12  赏尔  阅读(255)  评论(0编辑  收藏  举报