# 箱线图上色 import matplotlib.pyplot as plt list1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] c_list = ['#ef476f', '#ffd166', '#118AD5'] # 颜色代码列表 # 绘制箱线图 f = plt.boxplot(list1, vert=True, sym='+b', showmeans=True, meanline=True, patch_artist=True, widths=0.2) for box, c in zip(f['boxes'], c_list): # 对箱线图设置颜色 box.set(color=c, linewidth=2) box.set(facecolor=c) plt.show()
代码运行结果如图所示:
遇到问题欢迎联系博主,博主平时高强度网上冲浪,看到会回~