Last active
March 10, 2018 22:58
-
-
Save gebelo/c8141bdcff9c9559e946afa659b26354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib.colors import LinearSegmentedColormap | |
bins = [0,1] | |
# Maps values to a bin. | |
# The mapped values must start at 0 and end at 1. | |
def bin_mapping(x): | |
for idx, bound in enumerate(bins): | |
if x < bound: | |
return idx / (len(bins) - 1.0) | |
# Create the list of bin labels and the list of colors | |
# corresponding to each bin | |
bin_labels = [idx / (len(bins) - 1.0) for idx in range(len(bins))] | |
color_list = ['#edf8fb', '#b30000'] | |
# Create the custom color map | |
cmap = LinearSegmentedColormap.from_list('mycmap', | |
[(lbl, color) for lbl, color in zip(bin_labels, color_list)]) | |
for year in range(1990, 2017): | |
plot_col="RATIO"+str(year) | |
counties['Bin_Lbl'] = counties[plot_col].apply(bin_mapping) | |
mpl.pyplot.savefig(str(year) + 'map.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment