我有一个只允许 matplotlib 和基本 python 的作业。我无法生成所需的条形图。虽然 anaconda 已经确定了有问题的线路,但我无法理解。数据来源在这里:https : //data.gov.sg/dataset/bookings-for-new-flats-annual?view_id=2cdedc08-ddf6-4e0b-b279-82fdc7e678ea&resource_id=666ed30a-8344-4213-9deeafeddd77复制了一个示例资源并复制了它。import numpy as npimport matplotlib.pyplot as plt fname = "C:\data/bookings-for-new-flats.csv"data = np.genfromtxt('C:\data/bookings-for-new-flats.csv', skip_header=1, dtype=[('financial_year','U50'),('no_of_units','i8')], delimiter=",", missing_values=['na','-'],filling_values=[0])labels = list(set(data['financial_year']))labels.sort()bookings = np.arange(0,len(labels))bookings_values = data[['financial_year','no_of_units']]values = bookings_values['no_of_units']units_values = {}for i in labels: valuesforFY = values[bookings_values['financial_year']==i] print("No.of Units in FY: " + i + " is {}".format(valuesforFY)) #the line below is critical units_values[i] = valuesforFY barchart = plt.bar(list(units_values.keys()), list(units_values.values()), color='b')plt.show()期望一个条形图,但只收到一个空的。系统将此行识别为有问题 --->barchart = plt.bar(list(units_values.keys()), list(units_values.values()), color='b')
添加回答
举报
0/150
提交
取消