'Figure'对象不可调用



当我使用下面的代码创建一个图时,它产生了错误'Figure'对象是不可调用的。

奇怪的是,当我重新运行以前用于绘制其他早先工作的图形的代码时,我遇到了这个错误,我也开始得到相同的错误。

库导入:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import seaborn as sns
from datetime import datetime
from scipy import stats
from geopy import distance
from sklearn.linear_model import LinearRegression
%matplotlib inline
代码:

fig, ax = plt.subplots(1,2, figsize = (20,10))
ax0 = sns.scatterplot(ax = ax[0,0], x = df_delivery['Delivery Score'], y = df_delivery['Sales Percentile'])
ax1 = sns.scatterplot(ax = ax [0,1], x = df_delivery['Normalised Delivery'], y = df_delivery['Sales Percentile'])
ax0.set_title('Sales Percentile vs Delivery Score')
ax1.set_title('Sales Percentile vs Normalised Delivery')

错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-297-79a19867903b> in <module>
----> 1 fig, ax = plt.subplots(1,2, figsize = (20,10))
2 ax0 = sns.scatterplot(ax = ax[0,0], x = df_delivery['Delivery Score'], y = df_delivery['Sales Percentile'])
3 ax1 = sns.scatterplot(ax = ax [0,1], x = df_delivery['Normalised Delivery'], y = df_delivery['Sales Percentile'])
4 ax0.set_title('Sales Percentile vs Delivery Score')
5 ax1.set_title('Sales Percentile vs Normalised Delivery')
c:Usersclarianaconda3libsite-packagesmatplotlibpyplot.py in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1453 
1454     """
-> 1455     fig = figure(**fig_kw)
1456     axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
1457                        squeeze=squeeze, subplot_kw=subplot_kw,
TypeError: 'Figure' object is not callable

工作的早期代码(在我遇到错误后重新运行时不起作用)&错误信息:

plt.figure(figsize = (20,10))
sns.scatterplot(x = df_review['Review Score'], y = df_review['Sales Percentile'])
plt.show()
TypeError                                 Traceback (most recent call last)
<ipython-input-298-8370cbb7bf63> in <module>
1 #Plot Sales Percentile vs Review Score
2 
----> 3 plt.figure(figsize = (20,10))
4 sns.scatterplot(x = df_review['Review Score'], y = df_review['Sales Percentile'])
5 plt.show()
TypeError: 'Figure' object is not callable

您只需要在使用它之前导入您需要使用的函数。

例如,在中输入"import matplotlib"。pyplot plt的线显示错误mesg之前,遵循:

import pandas as pd
import numpy as np
from matplotlib.figure import Figure
from datetime import datetime
from scipy import stats
from geopy import distance
from sklearn.linear_model import LinearRegression
%matplotlib inline
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,2, figsize = (20,10))
import seaborn as sns
ax0 = sns.scatterplot(ax = ax[0,0], x = df_delivery['Delivery Score'], y 
= df_delivery['Sales Percentile'])
ax1 = sns.scatterplot(ax = ax [0,1], x = df_delivery['Normalised 
Delivery'], y = df_delivery['Sales Percentile'])
ax0.set_title('Sales Percentile vs Delivery Score')
ax1.set_title('Sales Percentile vs Normalised Delivery')

希望这行得通。

最新更新