【发布时间】:2017-10-03 19:11:15
【问题描述】:
我正在分析 FreeCodeCamp1 获取的 2016 年调查数据。 https://github.com/freeCodeCamp/2016-new-coder-survey
特别是 2016-new-coder-survey/clean-data/2016-FCC-New-Coders-Survey-Data.csv
由于某种原因,我想添加的任何其他图都不会显示。给出错误
raise AttributeError('Unknown property %s' % k)
AttributeError: Unknown property type
我的代码如下:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data_file = pd.read_csv('FCC_New_Coders_Survey_Data.csv', dtype={'AttendedBootcamp': float, 'CodeEventOther': object, 'JobRoleInterestOther': object})
AttendedBootcamp = data_file['AttendedBootcamp']
BootcampFullJobAfter = data_file['BootcampFullJobAfter']
BootcampRecommend = data_file['BootcampRecommend']
BootcampFinish = data_file['BootcampFinish']
Age = data_file['Age']
NetworkID = data_file['NetworkID']
AttendYes = data_file[data_file.AttendedBootcamp == 1]
AgeAttend = AttendYes['Age']
FinishYes = data_file[data_file.BootcampFinish == 1]
FinishNo = data_file[data_file.BootcampFinish == 0]
JobYes = data_file[data_file.BootcampFullJobAfter == 1]
JobNo = data_file[data_file.BootcampFullJobAfter == 0]
RecYes = data_file[data_file.BootcampRecommend == 1]
RecNo = data_file[data_file.BootcampRecommend == 0]
var = [len(JobYes[JobYes.Age == i]) - len(JobNo[JobNo.Age == i]) for i in range(16, 60)]
x = range(16, 60)
y = var
fig = plt.figure(figsize=(8,8))
plt.plot(x, y, 'go')
plt.xlabel('Age')
plt.ylabel('Net Employment Difference (count)')
plt.title('Employement Discrepencies')
plt.xticks(x)
plt.xscale('linear')
ax = fig.add_subplot(1, 1, 1)
ax.spines['bottom'].set_position('zero')
plt.vlines(x, [0], y)
ax.xaxis.set_ticks(np.arange(15, 65, 5))
plt.xlabel('Age', horizontalalignment='center', verticalalignment='center', x=1.05)
plt.show()
plt.figure(figsize=(8,8))
plt.title('bootcamp job')
plt.hist([JobYes['Age'], JobNo['Age']], histtype='bar', bins = 44, range=[16,60], label=['Job after camp', 'no job after camp'])
plt.xlabel('Age')
plt.ylabel('Count')
plt.legend()
plt.figure(figsize=(8,8))
plt.title('Attend bootcamp')
plt.hist(AttendYes['Age'], histtype='bar', range=[16,60])
plt.xlabel('Age')
plt.ylabel('Count')
plt.legend()
plt.figure(figsize=(8,8))
plt.title('bootcampfinish')
plt.hist([FinishYes['Age'], FinishNo['Age']], type='bar', range=[16,60], label=['finished', 'didn\'t finish'])
plt.xlabel('Age')
plt.ylabel('Count')
plt.legend()
var1 = [len(RecYes[RecYes.Age == j]) - len(RecNo[RecNo.Age == j]) for j in range(16, 60)]
x1 = range(16, 60)
y1 = var1
plt.figure(figsize=(8,8))
plt.plot(x1, y1)
plt.xlabel('Age')
plt.ylabel('Net reccomendation (count)')
plt.title('Age Sentiment')
plt.xticks(x1)
plt.xscale('linear')
plt.legend()
plt.show()
如果我要注释掉前四个情节之一,那么将显示第五个情节。
【问题讨论】:
-
matplotlib 中的图形数量没有硬性限制。有一个 rcParameter
figure.max_open_warning,默认设置为 20,所以一旦打开超过 20 个图形,就会出现警告。然而,仍然会显示更多的数字,只要内存允许。因此,错误的原因是不同的,可能与您的第 5 个图的参数之一有关。
标签: python matplotlib plot