【基础】学习笔记41-Python3 matplotlib绘图-并列柱形图

并列柱形图

运行结果为:


<备注:a、b、c的背景颜色设置;间距大小;柱形图宽度;标签位置在最中间等细节问题,可根据个人喜好进行设置>


代码如下:

# 柱形图:bar(left, height, width=0.8, bottom=None, **kwargs)

import matplotlib.pyplot as plt

import numpy as np

size = 5

x = np.arange(size)

a = np.random.random(size)

b = np.random.random(size)

c = np.random.random(size)

# ================并列柱形图===============

width = 0.8 / 3

plt.bar(x - width, a, width=width, color='r', label='a', alpha=0.5)

plt.bar(x, b, width=width, color='b', label='b', alpha=0.5)

plt.bar(x + width, c, width=width, color='g', label='c', alpha=0.5)

plt.legend(loc='upper left')

plt.show()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容