This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Gallery
Nico Schlömer edited this page Aug 9, 2021
·
1 revision
See https://matplotlib.org/stable/gallery/showcase/bachelors_degrees_by_gender.html.
import csv
import dufte
import matplotlib.pyplot as plt
import numpy as np
# read the data
filename = "percent_bachelors_degrees_women_usa.csv"
with open(filename) as f:
reader = csv.reader(f)
labels = next(reader)
labels = labels[1:]
#
data = np.array(np.genfromtxt(filename, delimiter=","))[1:]
year = data[:, 0]
data = data[:, 1:].T
# sort by last value
idx = np.argsort(-data[:, -1])
data = data[idx]
labels = [labels[i] for i in idx]
# create the plot
plt.style.use(dufte.style)
fig, ax = plt.subplots(1, 1, figsize=(12, 14))
for label, values in zip(labels, data):
ax.plot(year, values, label=label)
plt.title(
"Percentage of Bachelor's degrees conferred to women in "
"the U.S.A. by major (1970-2011)"
)
plt.ylim(0, 100)
ax.yaxis.set_major_formatter("{x:.0f}%")
dufte.legend()
plt.savefig("out.png", bbox_inches="tight")