43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
import pandas as pd
|
|
# import seaborn as sns
|
|
|
|
# Load data
|
|
marjobs = pd.read_csv("data/physician-marry.tsv", delimiter="\t")
|
|
marsorted = marjobs.sort_values(by=['p'], ascending=False)[0:49]
|
|
|
|
# Grid coordinates for a 7x7 grid
|
|
x = []
|
|
for i in range(0, 7):
|
|
x = x + list(range(0, 7))
|
|
y = list(reversed(np.repeat(np.arange(0,7), 7)))
|
|
|
|
# Prepare data for circles using bubble plot
|
|
mardf = pd.DataFrame({
|
|
"x" : x,
|
|
"y" : y,
|
|
"r" : list(marsorted.p * 50000),
|
|
"occname" : list(marsorted.occname),
|
|
"p" : list(marsorted.p * 100)
|
|
})
|
|
|
|
|
|
# Figure size
|
|
plt.rcParams['figure.figsize'] = (13, 13)
|
|
plt.rcParams['pdf.fonttype'] = 42
|
|
|
|
# Plot
|
|
plt.scatter("x", "y", s="r", data=mardf)
|
|
|
|
# Text
|
|
plt.rcParams['font.size'] = 8
|
|
plt.rcParams['pdf.fonttype'] = 42
|
|
for i in range(0, len(mardf)):
|
|
thelabel = str(round(mardf.p[i], 2)) + "%\n "
|
|
thelabel += mardf.occname[i]
|
|
plt.text(mardf.x[i], mardf.y[i], thelabel,
|
|
horizontalalignment="center")
|
|
|
|
# Save as PDF
|
|
plt.savefig("symbols-grid-mar.pdf") |