单个运行中显示了多少个matplotlib图有限制



我正在分析freecodecamp1获取的2016年调查数据。https://github.com/freecodecamp/2016-new-coder-survey

特别是,2016年 - 新编码 - survey/clean-data/2016-fcc-new-new-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()

如果我要发表评论说,那是前四个地块之一,则第五个图会显示。

您的问题不是绘图的数量,而是在呼叫第五个地块中的错别字。据我所知,地块数量没有限制(我猜除了您自己的计算机的内存)

在您的第五个图中,您正在调用plt.hist(..., type='bar'),例如前四个地块中的plt.hist(..., histtype='bar')

最新更新