一次运行显示多少matplotlib绘图有限制吗?

2024-10-01 07:34:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在分析FreeCodeCamp1拍摄的2016年调查数据。https://github.com/freeCodeCamp/2016-new-coder-survey

特别是2016年新编码器调查/清洁数据/2016年FCC新编码器调查-数据.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()

如果我要注释掉,比如说,前四个情节中的一个,那么第五个情节就会出现。你知道吗


Tags: agedatatitlerangepltfilefigurexlabel
1条回答
网友
1楼 · 发布于 2024-10-01 07:34:35

你的问题不在于绘图的数量,而在于对第五个绘图的调用有误。据我所知,绘图的数量是没有限制的(我想除了你自己的电脑内存之外)

在您的第五个绘图中,您正在调用plt.hist(..., type='bar'),而它应该是plt.hist(..., histtype='bar'),就像在前四个绘图中一样。你知道吗

相关问题 更多 >