python matplotlib bar图怎么画出这样的区间

Python025

python matplotlib bar图怎么画出这样的区间,第1张

最简单的柱状代码应该是这样

# coding: utf-8import matplotlib.pyplot as pltimport numpy as np

x = np.random.randint(0, 10, size=10)

y = np.random.randint(100, 1000, size=10)

plt.bar(x, y)

plt.show()

bar函数调用中添加输入参数hatch,例子如下:

import matplotlib.pyplot as plt

x1_value=1

y1_value=10

x2_value=2

y2_value=20

bar_width = 0.2

plt.bar(x1_value, y1_value, bar_width, hatch='*')

plt.bar(x2_value, y2_value, bar_width, hatch='/')

picName='test.png'

plt.savefig(output_path + picName, dpi=200)

结果:

关于hatch值的填法,可参考:https://matplotlib.org/api/patches_api.html#matplotlib.patches.Patch.set_hatch