Building a histogram or scatter plot using matplotlib

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"]

asian = race["asian"]
biracial = race["biracial"]
hispanic = race ["hispanic"]
white = race ["white"]
black = race["black"]
native_american = race["native american"]

all_race = [asian, biracial, hispanic, white, black, native_american]

plt.hist (all_race)
plt.show ()

Image of the current histogram:

Image of the current histogram

I want to change him so that he has the names of all races. the numbers on the x and y axis are incorrect, and I'm not sure how to fix this.

Some data:

enter image description here

+4
source share
1 answer

I think you want to use a histogram instead. Histograms are used to study the distribution of numerical data. Here's how I implement it:

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()
+2
source

All Articles