def get_dataframe_and_axes(): ''' arbitrary data for now ''' from bokeh.sampledata.unemployment1948 import data data['Year'] = data['Year'].astype(str) data = data.set_index('Year') data.drop('Annual', axis=1, inplace=True) data.columns.name = 'Month' years = list(data.index) 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() return df, years, months
from math import pi from bokeh.models import HoverTool from bokeh.plotting import ColumnDataSource, figure, show, output_file from bokeh.sampledata.unemployment1948 import data 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 = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"] # 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) color.append(colors[min(int(monthly_rate)-2, 8)])
from math import pi import pandas as pd from bokeh.io import show from bokeh.models import LinearColorMapper, BasicTicker, PrintfTickFormatter, ColorBar from bokeh.plotting import figure from bokeh.sampledata.unemployment1948 import data data['Year'] = data['Year'].astype(str) data = data.set_index('Year') data.drop('Annual', axis=1, inplace=True) data.columns.name = 'Month' years = list(data.index) 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 = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"] mapper = LinearColorMapper(palette=colors, low=df.rate.min(), high=df.rate.max()) TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom" p = figure(title="US Unemployment ({0} - {1})".format(years[0], years[-1]), x_range=years, y_range=list(reversed(months)), x_axis_location="above", plot_width=900, plot_height=400, tools=TOOLS, toolbar_location='below', tooltips=[('date', '@Month @Year'), ('rate', '@rate%')])
from math import pi from bokeh.models import HoverTool from bokeh.plotting import ColumnDataSource, figure, show, output_file from bokeh.sampledata.unemployment1948 import data 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 = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"] # 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) color.append(colors[min(int(monthly_rate) - 2, 8)]) source = ColumnDataSource(data=dict(month=month, year=year, color=color, rate=rate))
import cudf import pandas as pd from bokeh.sampledata.unemployment1948 import data data["Year"] = data["Year"].astype(str) data = data.set_index("Year") data.drop("Annual", axis=1, inplace=True) data.columns.name = "Month" years = list(data.index) 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() df["Month"] = pd.to_datetime(df.Month, format="%b").dt.month df["Year"] = df["Year"].astype("float64") df["Month"] = df["Month"].astype("float64") df = cudf.DataFrame.from_pandas(df)