折线图+箱型图 Python

1.折线图

import matplotlib.pyplot as plt
import numpy as np

with plt.style.context(('bmh')):
    fig, ax = plt.subplots(figsize=(20,10))
    x = np.arange(-2*np.pi,2*np.pi,0.1)
    y = np.sin(x)
    ax.set_yticks([-1,0,1])
    ax.plot(x,y,linestyle='-',marker='o')
    fig.show()

2.箱型图

fig, ax = plt.subplots(figsize=(20,10))
box = [np.random.uniform(i+0.7,i+1.3,1000) for i in range(3)]
for i in range(len(box)):
    x = np.random.uniform(i+0.7,i+1.3,1000)
    ax.plot(x, box[i], '.', alpha=1, markersize=1) 
ax.boxplot(box,
           labels=['A','B','C'],
           # 是否显示异常值       
           showfliers = False ,
           widths = 0.4,
           # 异常点
           flierprops = {'marker':'.','markerfacecolor':'black','color':'black','markersize':'1'},
           # 中线
           medianprops = {'linestyle':'-','color':'black'},
           # 
           capprops = {'linestyle':'-','linewidth':'1'})
fig.show()

你可能感兴趣的:(Python,Project)