使用matplotlib绘制直方图或散点图

时间:2016-04-29 18:50:54

标签: python matplotlib plot

ps -eo user,pid,%mem,command --sort=%mem

当前直方图的图像:

Image of current histogram

我想改变它,所以它有所有种族的名字。 x和y轴上的数字是错误的,我不知道如何解决它

部分数据:

enter image description here

1 个答案:

答案 0 :(得分:2)

我认为您想要使用的是条形图。直方图用于检查数值数据的分布。以下是我将如何实现它:

import matplotlib.pyplot as plt
import education
list_of_record = education.get_all_states

virginia_education = education.get_state('Virginia')
enrollment = virginia_education["enrollment"]
students = enrollment["students"]
race = students["race"]

x = range(len(race)) # x-axis list
label = [] # x-labels list
y = [] # y-values list
for race, value in race.items():
    label.append(race) # add race to x-labels list
    y.append(value) # add value to y-values list

plt.bar(x,y,color='indianred',tick_label=label,align='center')
plt.show()