簡體   English   中英

Python TypeError:xlabel()缺少1個必需的位置參數:“ s”

[英]Python TypeError: xlabel() missing 1 required positional argument: '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 (和ylabel )期望第一個參數是要使用的字符串( 請參見doc ),因此將plt.xlabel(label = "VOC", loc = 'best')替換為plt.xlabel("VOC") ,然后對ylabel做同樣的ylabel

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM