Add VT2-examples: all 6 chapters of 'Visualize This' (110 files) — data scraping, ETL, trends, categorical, multivariate, spatial, distribution analysis
This commit is contained in:
1 parent
088771a9cf
commit
b42b866a8c
110 files changed
+400895
No files matched your search
@@ -0,0 +1,43 @@
|
||||
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")
|
||||
Reference in new issue
Block a user