import numpy as np
import matplotlib.pyplot as plt
x = np.arange(1,5)
y = np.arange(5,9)
plt.bar(x,y,width=0.4)
plt.show()
设置标题和柱子上数字
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(1,5)
y = np.arange(5,9)
plt.barh(x,y)
for i,j in zip(x,y):
plt.text(j+0.1,i,j)
plt.xlabel("x")
plt.ylabel("y")
plt.title("x and y")
plt.show()