直接复制了别人的代码,提示有错误:
TypeError: bar() missing 1 required positional argument: ‘x’
以下是正确的代码:
import numpy as np
import os
import matplotlib.pyplot as plt
N = 5
y = [20,10,30,25,15]
y1 = np.random.randint(10,50,5)
x = np.random.randint(10,1000,N)
index = np.arange(N)
plt.bar(x = index,height=y,color='red',width=0.3)
plt.bar(x = index +0.3,height=y1,color='black',width=0.3)
plt.show()