data["Year"] = [str(x) for x in data["Year"]]
years = list(data["Year"])
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
data = data.set_index("Year")
// this is the colormap from the original NYTimes plot
colors = ["/f", "//a5bab7", "//c9d9d3", "//e2e2e2", "//dfccce", "//ddb7b1", "//cc7878", "/묽b41", "/릾b1d"]
mapper = LinearColorMapper(palette=colors)
// Set up the data for plotting. We will need to have values for every
// pair of year/month names. Map the rate to a color.
month = []
year = []
color = []
rate = []
for y in years:
for m in months:
month.append(m)
year.append(y)
monthly_rate = data[m][y]
rate.append(monthly_rate)
source = ColumnDataSource(
data=dict(month=month, year=year, rate=rate)
)
After Change
months = list(data.columns)
// reshape to 1D array or rates with a month and year for each row.
df = pd.DataFrame(data.stack(), columns=["rate"]).reset_index()
// this is the colormap from the original NYTimes plot
colors = ["/f", "//a5bab7", "//c9d9d3", "//e2e2e2", "//dfccce", "//ddb7b1", "//cc7878", "/묽b41", "/릾b1d"]
mapper = LinearColorMapper(palette=colors, low=df.rate.min(), high=df.rate.max())