Python TypeError:xlabel()缺少1个必需的位置参数:“ s”

时间:2019-03-14 09:07:15

标签: python

import os, pandas as pd
from matplotlib import pyplot
import matplotlib.pyplot as plt
#Change this to match your directory where the file is stored
os.chdir(r'Z:\\My Documents') 
#Read the CSV into Python, setting the first column as the index and    the     first row as the column names
series = pd.read_csv('Energy.csv', header=0,index_col = 0)
series = series.transpose() 
x = series.columns
print(series.head())

name = series.index.values
plt.figure(figsize = (11.69,8.27))

for i,values in enumerate(series.values):
    plt.bar(x,values, label = name[i])
    plt.xlabel(label = "VOC", loc = 'best')
    plt.ylabel(label = "VOC", loc = 'best')
plt.legend(loc = 'best')

大家好

我正在尝试运行上面的代码,并且一直在说:

TypeError: xlabel() missing 1 required positional argument: 's'

我已经移动了位置参数,但它仍然引发错误。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

xlabel(和ylabel)期望第一个参数是要使用的字符串(see doc here),因此将plt.xlabel(label = "VOC", loc = 'best')替换为plt.xlabel("VOC"),然后执行ylabel

也是一样