Python 类型错误:xlabel() 缺少 1 个必需的位置参数:'s'


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'

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

有什么想法?

xlabel(and ylabel)期望第一个参数是要使用的字符串(请参阅此处的文档),因此请用plt.xlabel("VOC")替换plt.xlabel(label = "VOC", loc = 'best'),然后对ylabel

最新更新