Python 如何正确处理';鄙视';函数以避免错误消息
我一直在使用Python 如何正确处理';鄙视';函数以避免错误消息,python,python-3.x,matplotlib,Python,Python 3.x,Matplotlib,我一直在使用skeene(plt.gca())作为绘制时间序列数据的工具,如下所示: %matplotlib inline import matplotlib.pyplot as plt import numpy as np import pandas as pd from datetime import datetime date_rng = pd.date_range(start='1/2015', end='1/2019', freq='M') #Let’s create an exa
skeene(plt.gca())
作为绘制时间序列数据的工具,如下所示:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from datetime import datetime
date_rng = pd.date_range(start='1/2015', end='1/2019', freq='M')
#Let’s create an example data frame with the timestamp data and look at the first 5
df = pd.DataFrame(date_rng, columns=['date'])
df['data'] = np.random.randint(0,100,size=(len(date_rng)))
df.head()
df['datetime'] = pd.to_datetime(df['date'])
df = df.set_index('datetime')
df.drop(['date'], axis=1, inplace=True)
df.head()
# we visualize the data:
df.plot(lw=1.5)
despine(plt.gca())
plt.gcf().autofmt_xdate()
plt.ylabel('Series');
上面的python代码给出了以下错误消息
NameError: name 'despine' is not defined
如果我按以下方式导入seaborn:
mport seaborn as sns
df.plot(lw=1.5)
sns.despine(plt.gca())
plt.gcf().autofmt_xdate()
plt.ylabel('Series');
它将产生以下错误:
'AxesSubplot' object is not iterable
虽然绘图已经完成,但我更希望没有任何错误消息。每次我使用特定代码行时,都会出现此错误消息
请帮我找出Skistine(plt.gca())有什么问题。我在Python3上运行这段代码您没有定义任何名为
的函数,也没有导入任何在其中定义了该函数的模块。假设您要使用,则需要导入模块,然后访问SKERINE函数:
import seaborn as sns
# Your code here
sns.despine(ax=plt.gca())
什么是轻视?你是说seaborn.skeene
?@DavidG是的,seaborn.skeene'AxesSubplot'对象不是iterable@DanielJames抱歉,错过了ax=
。我已经更新了我的答案,现在应该可以了