今天看啥  ›  专栏  ›  Alyna_C

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

Alyna_C  · 简书  ·  · 2020-12-18 00:19

并列柱形图

运行结果为:


<备注: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()




原文地址:访问原文地址
快照地址: 访问文章快照