# 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 pltx1_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