Boxplots
本文轉載自斗大的熊貓
簡單 Boxplots
import matplotlib.pyplot as plt import numpy as npall_data = [np.random.normal(0, std, 100) for std in range(1, 4)]fig = plt.figure(figsize=(8,6))plt.boxplot(all_data,notch=False, # box instead of notch shapesym='rs', # red squares for outliersvert=True) # vertical box aligmnentplt.xticks([y+1 for y in range(len(all_data))], ['x1', 'x2', 'x3']) plt.xlabel('measurement x') t = plt.title('Box plot') plt.show()黑白盒狀圖
import matplotlib.pyplot as plt import numpy as npall_data = [np.random.normal(0, std, 100) for std in range(1, 4)]fig = plt.figure(figsize=(8,6))bplot = plt.boxplot(all_data,notch=False, # box instead of notch shapesym='rs', # red squares for outliersvert=True) # vertical box aligmnentplt.xticks([y+1 for y in range(len(all_data))], ['x1', 'x2', 'x3']) plt.xlabel('measurement x')for components in bplot.keys():for line in bplot[components]:line.set_color('black') # black linest = plt.title('Black and white box plot')plt.show()自定義顏色填充盒狀圖
import matplotlib.pyplot as plt import numpy as npall_data = [np.random.normal(0, std, 100) for std in range(1, 4)]fig = plt.figure(figsize=(8,6))bplot = plt.boxplot(all_data,notch=False, # notch shapevert=True, # vertical box aligmnentpatch_artist=True) # fill with colorcolors = ['pink', 'lightblue', 'lightgreen'] for patch, color in zip(bplot['boxes'], colors):patch.set_facecolor(color)plt.xticks([y+1 for y in range(len(all_data))], ['x1', 'x2', 'x3']) plt.xlabel('measurement x') t = plt.title('Box plot') plt.show()小提琴
import matplotlib.pyplot as plt import numpy as npfig, axes = plt.subplots(nrows=1,ncols=2, figsize=(12,5))all_data = [np.random.normal(0, std, 100) for std in range(6, 10)]#fig = plt.figure(figsize=(8,6))axes[0].violinplot(all_data,showmeans=False,showmedians=True) axes[0].set_title('violin plot')axes[1].boxplot(all_data,) axes[1].set_title('box plot')# adding horizontal grid lines for ax in axes:ax.yaxis.grid(True)ax.set_xticks([y+1 for y in range(len(all_data))], )ax.set_xlabel('xlabel')ax.set_ylabel('ylabel')plt.setp(axes, xticks=[y+1 for y in range(len(all_data))],xticklabels=['x1', 'x2', 'x3', 'x4'],)plt.show()總結
- 上一篇: tensorflow 风格迁移二
- 下一篇: 图像识别 43个模型