Files
visual-data/VT2-examples/vt2-ch5-codedata-dir/make-symbols-chart.py
T

40 lines
979 B
Python

import matplotlib.pyplot as plt
import pandas as pd
# import seaborn as sns
# import math
# Load data
marjobs = pd.read_csv("data/physician-marry.tsv", delimiter="\t")
marsorted = marjobs.sort_values(by=['p'],
ascending=False)[0:10] # Top 10.
# Prepare data for circles using bubble plot
mardf = pd.DataFrame({
"x": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"y": [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
"r": list(marsorted.p * 50000)
})
# sns.set(rc={'pdf.fonttype': 42 })
# p1 = sns.relplot(x="x", y="y", size="r", sizes=(40,2000), data=mardf)
# fig = p1.get_figure()
# p1.savefig("symbols-chart-mar.pdf")
# Figure size
plt.rcParams['figure.figsize'] = (7, 10)
plt.rcParams['pdf.fonttype'] = 42
# Plot
plt.scatter("x", "y", s="r", data=mardf)
# Text
for i in range(0, len(marsorted)):
thelabel = str(round(100*marsorted.iloc[i].p)) + "%, "
thelabel += marsorted.iloc[i].occname
plt.text(1, 10-i, thelabel)
# Save as PDF
plt.savefig("symbols-chart-mar.pdf")