#画饼图
def print_pie(input_data):
res = {}
for each in input_data:
res[each] = res.get(each, 0) + 1
label=[]
X=[]
for j in res:
label.append(j)
X.append(res[j])
fig = plt.figure()
plt.pie(X,labels=label,autopct='%1.2f%%') #画饼图(数据,数据对应的标签,百分数保留两位小数点)
plt.title("Pie chart")
plt.show()
#
#频率直方图
plt.hist(df1['age'],100,normed=1,histtype='bar',facecolor='yellowgreen',alpha=0.75)
plt.show()
#频率直方图
plt.hist(df1['age'],100,normed=1,histtype='bar',facecolor='yellowgreen',alpha=0.75)
plt.show()
fig,(ax0,ax1) = plt.subplots(nrows=2,figsize=(9,6))
#第二个参数是柱子宽一些还是窄一些,越大越窄越密
ax0.hist(df1['age'],100,normed=1,histtype='bar',facecolor='yellowgreen',alpha=0.75)
ax0.set_title('YES')
ax1.hist(df2['age'],100,normed=1,histtype='bar',facecolor='PINK',alpha=0.75)
ax1.set_title("NO")
fig.subplots_adjust(hspace=0.4)
plt.show()
数据可视化
最新推荐文章于 2024-04-01 11:11:28 发布