In [1]:
import pandas
import matplotlib
from matplotlib import pyplot
%matplotlib inline
### Reading in data
data = pandas.read_csv('states_data.csv')
print(data.head(7))
In [2]:
pop = data['population_million']
votes = data['electoral_votes']
dems = (data['party_2016'] == 'D')
reps = (data['party_2016'] == 'R')
figure, ax = pyplot.subplots()
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
In [3]:
figure, ax = pyplot.subplots(figsize=(3, 2))
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
In [4]:
figure, ax = pyplot.subplots()
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
### set title and axis labels
ax.set_title('Electoral votes by state in the USA', size=16)
ax.set_xlabel('Population (millions)', size=16)
ax.set_ylabel('Electoral Votes per million', size=16)
Out[4]:
In [5]:
figure, ax = pyplot.subplots()
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
### set title and axis labels
ax.set_title('Electoral votes by state in the USA', size=15)
ax.set_xlabel('Population (millions)', size=15)
ax.set_ylabel('Electoral Votes per million', size=15)
### set axis labelsize
ax.xaxis.set_tick_params(labelsize=14)
ax.yaxis.set_tick_params(labelsize=14)
In [6]:
figure, ax = pyplot.subplots()
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
### set title and axis labels
ax.set_title('Electoral votes by state in the USA', size=15)
ax.set_xlabel('Population (millions)', size=15)
ax.set_ylabel('Electoral Votes per million', size=15)
### set axis labelsize
ax.xaxis.set_tick_params(labelsize=14)
ax.yaxis.set_tick_params(labelsize=14)
### set x-axis to logarithmic scale
ax.set_xscale('log')
### set tick values and labels
ax.xaxis.set_ticks([0.1, 1, 10, 100])
ax.xaxis.set_ticklabels(['0.1', '1', '10', '100'])
ax.xaxis.set_ticklabels(['point one', 'one', 'ten', 'one hundred'])
### set axis range
ax.set_ylim(0, 6)
Out[6]:
In [7]:
figure, ax = pyplot.subplots()
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
### set title and axis labels
ax.set_title('Electoral votes by state in the USA', size=15)
ax.set_xlabel('Population (millions)', size=15)
ax.set_ylabel('Electoral Votes per million', size=15)
### set axis labelsize
ax.xaxis.set_tick_params(labelsize=14)
ax.yaxis.set_tick_params(labelsize=14)
### set x-axis to logarithmic scale
ax.set_xscale('log')
### set tick values and labels
ax.xaxis.set_ticks([0.1, 1, 10, 100])
ax.xaxis.set_ticklabels(['0.1', '1', '10', '100'])
### set axis range
ax.set_ylim(0, 6)
### add minor ticks
ax.minorticks_on()
### add a grid
ax.grid()
In [ ]:
In [ ]:
In [ ]:
In [8]:
import pandas
import matplotlib
from matplotlib import pyplot
%matplotlib inline
matplotlib.rc_file('./rcfile_dir/matplotlibrc_atomczak')
### Reading in data
data = pandas.read_csv('states_data.csv')
pop = data['population_million']
votes = data['electoral_votes']
dems = data['party_2016'] == 'D'
reps = data['party_2016'] == 'R'
figure, ax = pyplot.subplots()
points1 = pyplot.plot(pop[reps], (votes/pop)[reps], ls='', marker='o', ms=8, mfc='red')
points2 = pyplot.plot(pop[dems], (votes/pop)[dems], ls='', marker='o', ms=8, mfc='blue')
### set title and axis labels
ax.set_title('Electoral votes by state in the USA')
ax.set_xlabel('Population (millions)')
ax.set_ylabel('Electoral Votes per million')
ax.set_xscale('log')
In [ ]: