@justinholman/

SeabornCompareDistributions

Python

No description

fork
loading
Files
  • main.py
  • 01-swarm.png
  • 02-box.png
  • 03-strip.png
  • 04-stripj.png
  • 05-strip-d1.png
  • 06-strip-jd2.png
  • 07-strip51.png
  • 08-box51.png
  • e08div.csv

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.17550841642167936","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyBmaXJzdCB3ZSBpbXBvcnQgbWF0cGxvdGxpYiBhbmQgdXNlKCdBZ2cnKSBzbyB3ZSBjYW4gInNhdmVmaWciIGJlbG93CmltcG9ydCBtYXRwbG90bGliIGFzIG1wbAptcGwudXNlKCdBZ2cnKQoKIyBub3cgbGV0cyBpbXBvcnQgdGhlIG90aGVyIG1vZHVsZXMgd2UgbmVlZAppbXBvcnQgcGFuZGFzIGFzIHBkCmltcG9ydCBzZWFib3JuIGFzIHNucwppbXBvcnQgbWF0cGxvdGxpYi5weXBsb3QgYXMgcGx0CgojIHdpdGggYWxsIG91ciBtb2R1bGVzIGluIHBsYWNlLCBsZXQncyByZWFkIGNzdiBkYXRhCmUwOCA9IHBkLnJlYWRfY3N2KCdlMDhkaXYuY3N2JykgCgojIG1ha2UgYSBzd2FybXBsb3QgdG8gc2hvdyBkaXN0IG9mIHZvdGUgYnkgY2Vuc3VzIHJlZ2lvbgpfID0gc25zLnN3YXJtcGxvdCh4PSdSZWdpb24nLCB5PSdkZW1fc2hhcmUnLCBkYXRhPWUwOCkKXyA9IHBsdC54bGFiZWwoJ1JlZ2lvbicpCl8gPSBwbHQueWxhYmVsKCclIFZvdGUgdG8gT2JhbWEnKQpwbHQuc2hvdygpCnBsdC5zYXZlZmlnKCcwMS1zd2FybS5wbmcnKQpwbHQuY2xmKCkKCiMgdHJ5IGJveHBsb3RzIApzbnMuYm94cGxvdCh4PSdSZWdpb24nLCB5PSdkZW1fc2hhcmUnLCBkYXRhPWUwOCwgcGFsZXR0ZT0iUFJHbiIpCl8gP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IFZvdGUgdG8gT2JhbWEnKQpwbHQuc2hvdygpCnBsdC5zYXZlZmlnKCcwNi1zdHJpcC1qZDIucG5nJykKcGx0LmNsZigpCgojIGNhbiB3ZSBmaXQgYWxsIDUwIFN0YXRlcyBvbiBhIHN0cmlwIHBsb3Q/Cl8gPSBzbnMuc3RyaXBwbG90KHg9J3N0YXRlJywgeT0nZGVtX3NoYXJlJywgZGF0YT1lMDgpCl8gPSBwbHQueGxhYmVsKCdSZWdpb24nKQpfID0gcGx0LnlsYWJlbCgnJSBWb3RlIHRvIE9iYW1hJykKcGx0LnNob3coKQpwbHQuc2F2ZWZpZygnMDctc3RyaXA1MS5wbmcnKQpwbHQuY2xmKCkKCiMgaG93IGFib3V0IGFsbCA1MCBzdGF0ZXMgb24gYSBob3Jpem9udGFsIGJveHBsb3Q/CnNucy5ib3hwbG90KHg9J2RlbV9zaGFyZScsIHk9J3N0YXRlJywgZGF0YT1lMDgsIG9yaWVudD0iaCIpCl8gPSBwbHQueGxhYmVsKCclIFZvdGUgdG8gT2JhbWEnKQpfID0gcGx0LnlsYWJlbCgnU3RhdGUnKQpwbHQuc2hvdygpCnBsdC5zYXZlZmlnKCcwOC1ib3g1MS5wbmcnKQpwbHQuY2xmKCk="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# first we import matplotlib and use('Agg') so we can "savefig" below
import matplotlib as mpl
mpl.use('Agg')

# now lets import the other modules we need
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# with all our modules in place, let's read csv data
e08 = pd.read_csv('e08div.csv') 

# make a swarmplot to show dist of vote by census region
_ = sns.swarmplot(x='Region', y='dem_share', data=e08)
_ = plt.xlabel('Region')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('01-swarm.png')
plt.clf()

# try boxplots 
sns.boxplot(x='Region', y='dem_share', data=e08, palette="PRGn")
_ = plt.xlabel('Region')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('02-box.png')
plt.clf()

# try stripplots
_ = sns.stripplot(x='Region', y='dem_share', data=e08)
_ = plt.xlabel('Region')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('03-strip.png')
plt.clf()

# add jitter
_ = sns.stripplot(x='Region', y='dem_share', data=e08, jitter=True)
_ = plt.xlabel('Region')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('04-stripj.png')
plt.clf()

# try stripplots with Divisions
_ = sns.stripplot(x='Division', y='dem_share', data=e08)
_ = plt.xlabel('Division')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('05-strip-d1.png')
plt.clf()

# add jitter
_ = sns.stripplot(x='Division', y='dem_share', data=e08, jitter=True)
_ = plt.xlabel('Division')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('06-strip-jd2.png')
plt.clf()

# can we fit all 50 States on a strip plot?
_ = sns.stripplot(x='state', y='dem_share', data=e08)
_ = plt.xlabel('Region')
_ = plt.ylabel('% Vote to Obama')
plt.show()
plt.savefig('07-strip51.png')
plt.clf()

# how about all 50 states on a horizontal boxplot?
sns.boxplot(x='dem_share', y='state', data=e08, orient="h")
_ = plt.xlabel('% Vote to Obama')
_ = plt.ylabel('State')
plt.show()
plt.savefig('08-box51.png')
plt.clf()