Skip to content

Instantly share code, notes, and snippets.

@andersonfrailey
Created February 3, 2018 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonfrailey/617b82053d36952072dc643ab1c61c1b to your computer and use it in GitHub Desktop.
Save andersonfrailey/617b82053d36952072dc643ab1c61c1b to your computer and use it in GitHub Desktop.
def plot(cds_list, year):
def ticker():
"""
function used to create the y-axis labels in the plot
"""
if tick == 25:
return 'All Taxpayers'
elif tick == 21:
return '$1M or more'
elif tick == 18.75:
return '$500K to $1M'
elif tick == 16.5:
return '$200K to $500K'
elif tick == 14.25:
return '$100K to 200K'
elif tick == 12:
return '$75K to $100K'
elif tick == 9.75:
return '$50K to $75K'
elif tick == 7.5:
return '$40K to 50K'
elif tick == 5.25:
return '$30K to $40K'
elif tick == 3:
return '$20K to $30K'
elif tick == 0.75:
return '$10K to $20K'
elif tick == -1.5:
return 'Less than $10K'
f = figure(title='Change in Tax Liability for {}'.format(year), width=900)
# add the row for all tax units separetly to make spacing easier
h0 = f.hbar(y=25, height=2, left='bottom', right='large_cut', color='darkblue', fill_alpha=0.75,
line_alpha=0.25, source=cds_list[0])
h1 = f.hbar(y=25, height=2, left='large_cut', right='small_cut', color='lightblue', fill_alpha=0.75,
line_alpha=0.25, source=cds_list[0])
h2 = f.hbar(y=25, height=2, left='small_cut', right='no_change', color='grey', fill_alpha=0.75,
line_alpha=0.25, source=cds_list[0])
h3 = f.hbar(y=25, height=2, left='no_change', right='small_inc', color='yellow', fill_alpha=0.75,
line_alpha=0.25, source=cds_list[0])
h4 = f.hbar(y=25, height=2, left='small_inc', right='large_inc', color='orange', fill_alpha=0.75,
line_alpha=0.25, source=cds_list[0])
y_val = 21
# add each income group to the plot
for item in cds_list[1:]:
f.hbar(y=y_val, height=2, left='bottom', right='large_cut', color='darkblue',
fill_alpha=0.75, line_alpha=0.25, source=item)
f.hbar(y=y_val, height=2, left='large_cut', right='small_cut', color='lightblue',
fill_alpha=0.75, line_alpha=0.25, source=item)
f.hbar(y=y_val, height=2, left='small_cut', right='no_change', color='grey',
fill_alpha=0.75, line_alpha=0.25, source=item)
f.hbar(y=y_val, height=2, left='no_change', right='small_inc', color='yellow',
fill_alpha=0.75, line_alpha=0.25, source=item)
f.hbar(y=y_val, height=2, left='small_inc', right='large_inc', color='orange',
fill_alpha=0.75, line_alpha=0.25, source=item)
y_val -= 2.25
# general plot formatting
legend = Legend(items=[('Decrease > $500', [h0]),
('Decrease $100-500', [h1]),
('Less than $100 Change', [h2]),
('Increase $100-500', [h3]),
('Increase > $500', [h4])],
orientation='horizontal')
f.add_layout(legend, 'above')
f.yaxis.formatter = FuncTickFormatter.from_py_func(ticker)
f.yaxis.ticker = [-1.5, 0.75, 3, 5.25, 7.5, 9.75, 12, 14.25, 16.5, 18.75, 21, 25, 30]
f.xaxis.ticker = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
f.xaxis[0].formatter = NumeralTickFormatter(format='0.%')
f.xgrid.minor_grid_line_alpha = 0.1
return f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment