plt.bar中的元组对象不可调用错误

时间:2016-11-25 17:12:08

标签: python matplotlib

我有一个熊猫数据框,其中包含Facebook参与数据以及出勤和"主题"有关一系列事件的信息。数据框称为df:

FBDataSet = [["Saturday, June 16, 2012", "Desert Oasis", 25417, DesertOasis_postIDs, 121, 23, "Spring"], 
         ["Saturday, November 17, 2012", "The Golden Era", 15926, GoldenEra_postIDs, 797, 76, "Fall"], 
         ["Saturday, June 15, 2013", "The White Party 2013", 23509, WhiteParty13_postIDs, 667, 121, "Spring"], 
         ["Saturday, June 22, 2013", "Boots, Brew & BBQ 2013", 20034, BBQ13_postIDs, 1136, 195, "Spring"],
         ["Saturday, September 7, 2013", "College Rivalry Night 2013", 13900, CollegeRivalry13_postIDs, 2151, 403, "September"],
         ["Saturday, September 28, 2013", "Homecoming Dance", 15400, Homecoming_postIDs, 2636, 346, "Fall"],
         ["Saturday, November 16, 2013", "My Fall Derby Style", 12222, FallDerbyStyle_postIDs, 2097, 309, "Fall"],
         ["Saturday, April 26, 2014", "Opening Night 2014", 24431, OpeningNight14_postIDs, 2547, 443, "Spring"],
         ["Saturday, June 14, 2014", "The White Party 2014", 21671, WhiteParty14_postIDs, 1561, 231, "Spring"],
         ["Friday, June 27, 2014", "Rockin' in the USA", 18193, RockinUSA_postIDs, 342, 64, "Spring"],
         ["Friday, September 5, 2014", "College Rivalry Night 2014", 11058, CollegeRivalry14_postIDs, 1187, 243, "September"],
         ["Friday, September 19, 2014", "Oktoberfest", 14212, Oktoberfest_postIDs, 2467, 575, "September"],
         ["Saturday, June 13, 2015", "The White Party 2015", 28968, WhiteParty15_postIDs, 4631, 538, "Spring"],
         ["Saturday, June 27, 2015", "Boots, Brew & BBQ 2015", 24192, BBQ15_postIDs, 811, 105, "Spring"],
         ["Saturday, September 19, 2015", "Summer Sunset", 14786, SummerSunset_postIDs, 2435, 376, "September"],
         ["Saturday, June 18, 2016", "The White Party 2016", 19034, WhiteParty16_postIDs, 273, 40, "Spring"],
         ["Saturday, July 2, 2016", "My Country Tis of Thee", 19621, MCTOT_postIDs, 226, 48, "Spring"],
         ["Saturday, September 24, 2016", "Bourbon, Bets & Bowties", 16768, BourbonBetsBowties_postIDs, 2470, 393, "September"]]

import pandas as pd
df = pd.DataFrame(FBDataSet)
df.columns = ["Date", "Theme", "Attendance", "PostIDs", "Likes", "Shares", "Meet"]

我通过从该数据框中提取列来创建变量:

All_Likes = df["Likes"]
All_Attendance = df["Attendance"]
All_Shares = df["Shares"]
All_Themes = df["Theme"]

我在"主题"中列出了各个样本。专栏:

All_Themeslist=[]
for x in All_Themes:
    All_Themeslist.append(x)

为了准备我的plt.bar图表,我设置了正确的xpositions数量:

xpositions = np.arrange(18)

我尝试使用以下代码生成条形图:

plt.bar(xpositions, All_Likes)
plt.xticks(xpositions, All_Themeslist, rotation=90)
plt.show()

我收到以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-521-b7ee361aed7a> in <module>()
     1 plt.bar(xpositions, All_Likes)
     ----> 2 plt.xticks(xpositions, All_Themeslist, rotation=90)
     3 plt.show()

TypeError: 'tuple' object is not callable

所以我的代码似乎无法从我的列表中调用各个主题名称&#34; All_Themeslist&#34;它正在将其视为元组。

我想要的输出是将喜欢的数字显示为条形图,每个条形图在X轴上用列表中的主题标记为&#34; All_Themeslist。&#34;

我做错了什么?

编辑:导入代码:

%matplotlib inline
import matplotlib.pyplot as plt
plt.ioff()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np

我还尝试将元组转换为字符串:

Names = []
for x in All_Themeslist:
    Names.append
Names = str(Names)
然后我替换了新的str变量&#34; Names&#34; for&#34; All_Themeslist&#34;在原始代码中。相同的结果。

0 个答案:

没有答案