先导入库:
import matplotlib.pyplot as plt import numpy as np 定义参数: x = np.arange(5) y1 = np.array([12, 8, 10, 11, 15]) # 柱形高度 bar_width = 0.3 # 绘制柱形图 plt.bar(x, y1, tick_label=['E', 'F', 'G', 'H', 'J'], width=bar_width)
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(5)
y1 = np.array([12, 8, 10, 11, 15])
# 柱形高度
bar_width = 0.3
# 绘制柱形图
plt.bar(x, y1, tick_label=['E', 'F', 'G', 'H', 'J'], width=bar_width)
# 显示图形
plt.show()
显示图像:
plt.show