def create_plot(): (candidatos, porcentajes) = get_plot_data() # (candidatos, porcentajes) = json_load_unicode("databokeh.json") primero, segundo = porcentajes[:2] falta = min(45, max(40 , (segundo + 10))) - primero if falta <= 0: sobra = -falta fserie = [sobra] + [0] * 5 porcentajes[0] -= sobra resultado = "Gana %s en Primera Vuelta" % candidatos[0] PALETTE = ["#54BBE2", "#5EDF4D"] data = OrderedDict([("porcentajes", porcentajes), ("sobra", fserie)]) else: PALETTE = ["#54BBE2", "#E5162A"] fserie = [falta] + [0] * 5 resultado = "Hay Ballotage" data = OrderedDict([("porcentajes", porcentajes), ("falta", fserie)]) # build a dict containing the grouped data output_file("primervueltometro.html") # Flyer derecho fijo : 300 x 500 # Zonas de columna auxiliar : 300 x 300 (1er y 2do rolado) # Puente largo : 975 x 80 # Puente corto : 650 x 80 width, height = 300, 300 z = 2 width *= z height *= z params = { "title": resultado, "stacked": True, "width": width, "height": height, "tools": "", "palette": PALETTE, "legend": 'top_right' } bar = Bar(data, candidatos, **params) show(bar)
def create_plot(): candidatos, (porcentajes, falta) = get_plot_data() if falta <= 0: sobra = -falta fserie = [sobra] + [0] * 5 porcentajes[0] -= sobra resultado = "Gana %s en Primera Vuelta" % candidatos[0] data = OrderedDict([("porcentajes", porcentajes), ("sobra", fserie)]) else: fserie = [falta] + [0] * 5 resultado = "Hay Ballotage" data = OrderedDict([("porcentajes", porcentajes), ("falta", fserie)]) # build a dict containing the grouped data output_file("primervueltometro.html") # Flyer derecho fijo : 300 x 500 # Zonas de columna auxiliar : 300 x 300 (1er y 2do rolado) # Puente largo : 975 x 80 # Puente corto : 650 x 80 width, height = 300, 300 z = 2 width *= z height *= z params = { "title": "PrimerVueltómetro: %s" % resultado, "stacked": True, "width": width, "height": height, "tools": "", "palette": PALETTE, "legend": 'top_right' } bar = Bar(data, candidatos, **params) show(bar)
from collections import OrderedDict from bokeh._legacy_charts import Dot, show, output_file from bokeh.charts import Dot # create some example data xyvalues = OrderedDict( python=[2, 3, 7, 5, 26], pypy=[12, 33, 47, 15, 126], jython=[22, 43, 10, 25, 26], ) output_file("dots.html") from bokeh.charts import Bar, output_file, show, hplot # best support is with data in a format that is table-like data = { 'sample': ['1st', '2nd', '1st', '2nd', '1st', '2nd'], 'interpreter': ['python', 'python', 'pypy', 'pypy', 'jython', 'jython'], 'timing': [-2, 5, 12, 40, 22, 30] } # x-axis labels pulled from the interpreter column, stacking labels from sample column dots = Dot(data, values='timing', label='interpreter', group='sample', agg='mean', title="Python Interpreter Sampling", legend='top_right', width=600) show(dots)
from collections import OrderedDict from bokeh._legacy_charts import Dot, show, output_file # create some example data xyvalues = OrderedDict( python=[2, 3, 7, 5, 26], pypy=[12, 33, 47, 15, 126], jython=[22, 43, 10, 25, 26], ) # any of the following commented are also valid Dot inputs #xyvalues = pd.DataFrame(xyvalues) #xyvalues = list(xyvalues.values()) #xyvalues = np.array(list(xyvalues.values())) output_file("dots.html") dots = Dot( xyvalues, cat=['lists','loops','dicts', 'gen exp', 'exceptions'], title="Dots Example", ylabel='Performance', legend=True ) show(dots)
from os.path import dirname, join from blaze import Data from bokeh.sampledata import iris from bokeh._legacy_charts import Line, show, output_file bbvalues = Data(join(dirname(iris.__file__), 'iris.csv')) columns = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width'] result = bbvalues[columns] output_file("blaze_input.html") line = Line( result, title="Line Chart", ylabel='Petals', notebook=True, legend="top_left" ) show(line)
("RdPu9", RdPu9), ("RdYlBu9", RdYlBu9), ("RdYlGn9", RdYlGn9), ("Reds9", Reds9), ("Spectral9", Spectral9), ("YlGn9", YlGn9), ("YlGnBu9", YlGnBu9), ("YlOrBr9", YlOrBr9), ("YlOrRd9", YlOrRd9)]) def create_area_chart(data, palette): _chart_styling = dict(height=300, width=300, xgrid=False, ygrid=False, tools=None) return Area(data, title=palette, stacked=True, palette=standard_palettes.get(palette), **_chart_styling) data = np.random.random_integers(low=5, high=13, size=[9, 20]) area_charts = [ create_area_chart(data, palette) for palette in standard_palettes.keys() ] area_charts = np.reshape(area_charts, newshape=[9, 3]).tolist() output_file('palettes.html', title='palettes.py example') show(gridplot(area_charts))
from os.path import dirname, join from blaze import Data from bokeh.sampledata import iris from bokeh._legacy_charts import Line, show, output_file bbvalues = Data(join(dirname(iris.__file__), 'iris.csv')) columns = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width'] result = bbvalues[columns] output_file("blaze_input.html") line = Line(result, title="Line Chart", ylabel='Petals', notebook=True, legend="top_left") show(line)
from bokeh._legacy_charts import HeatMap, output_file, show from bokeh.palettes import YlOrRd9 as palette from bokeh.sampledata.unemployment1948 import data # pandas magic df = data[data.columns[:-1]] df2 = df.set_index(df[df.columns[0]].astype(str)) df2.drop(df.columns[0], axis=1, inplace=True) df3 = df2.transpose() output_file("cat_heatmap.html") palette = palette[::-1] # Reverse the color order so dark red is highest unemployment hm = HeatMap(df3, title="categorical heatmap", width=800, palette=palette) show(hm)
xyvalues = OrderedDict( AAPL=AAPL['Adj Close'], Date=AAPL['Date'], MSFT=MSFT['Adj Close'], IBM=IBM['Adj Close'], ) # any of the following commented are valid Bar inputs #xyvalues = pd.DataFrame(xyvalues) #lindex = xyvalues.pop('Date') #lxyvalues = list(xyvalues.values()) #lxyvalues = np.array(xyvalues.values()) TOOLS = "resize,pan,wheel_zoom,box_zoom,reset,previewsave" output_file("stocks_timeseries.html") ts = TimeSeries(xyvalues, index='Date', legend=True, title="Timeseries", tools=TOOLS, ylabel='Stock Prices') # usage with iterable index #ts = TimeSeries( # lxyvalues, index=lindex, # title="timeseries, pd_input", ylabel='Stock Prices') show(ts)
from collections import OrderedDict import numpy as np from bokeh._legacy_charts import Horizon, output_file, show x = np.linspace(0, np.pi*4, 137) y = (2*np.random.normal(size=137) + x**2) xx = np.hstack([-1*x[::-1], x]) yy = np.hstack([-1*y[::-1], y]) xyvalues = OrderedDict(x=xx, y=yy, y2=yy, y3=yy, y4=yy, y5=yy) output_file("horizon_folds.html") hp = Horizon(xyvalues, index='x', title="test horizon", ylabel='Random') show(hp)
# throw the data into a pandas data frame df = pd.io.json.json_normalize(data['data']) # filter by countries with at least one medal and sort df = df[df['medals.total'] > 8] df = df.sort("medals.total", ascending=False) # get the countries and we group the data by medal type countries = df.abbr.values.tolist() gold = df['medals.gold'].astype(float).values silver = df['medals.silver'].astype(float).values bronze = df['medals.bronze'].astype(float).values # build a dict containing the grouped data medals = OrderedDict() medals['bronze'] = bronze medals['silver'] = silver medals['gold'] = gold # any of the following commented are also valid Donut inputs #medals = list(medals.values()) #medals = np.array(list(medals.values())) #medals = pd.DataFrame(medals) output_file("donut.html") donut = Donut(medals, countries) show(donut)
("PuRd9", PuRd9), ("Purples9", Purples9), ("RdBu9", RdBu9), ("RdGy9", RdGy9), ("RdPu9", RdPu9), ("RdYlBu9", RdYlBu9), ("RdYlGn9", RdYlGn9), ("Reds9", Reds9), ("Spectral9", Spectral9), ("YlGn9", YlGn9), ("YlGnBu9", YlGnBu9), ("YlOrBr9", YlOrBr9), ("YlOrRd9", YlOrRd9)]) def create_area_chart(data, palette): _chart_styling = dict(height=300, width=300, xgrid=False, ygrid=False, tools=None) return Area(data, title=palette, stacked=True, palette=standard_palettes.get(palette), **_chart_styling) data = np.random.random_integers(low=5, high=13, size=[9,20]) area_charts = [create_area_chart(data, palette) for palette in standard_palettes.keys()] area_charts = np.reshape(area_charts, newshape=[9,3]).tolist() output_file('palettes.html', title='palettes.py example') show(gridplot(area_charts))
palette=palette, title="categorical heatmap, pd_input", height=400, width=1000) hm_data = df3.values.T hm2 = HeatMap(hm_data, palette=palette, title="Unemployment (Array)", xlabel='Years since 1948', ylabel='Months', height=400, width=1000) simple_df = pd.DataFrame( { 'apples': [4, 5, 8, 12, 4], 'pears': [6, 5, 4, 8, 7], 'bananas': [1, 2, 4, 8, 12] }, index=['2009', '2010', '2011', '2012', '2013']) hm3 = HeatMap(simple_df, palette=palette, title="Fruit comsumption per year", height=400, width=1000) output_file("heatmap.html") show(vplot(hm1, hm2, hm3))
from collections import OrderedDict import pandas as pd from bokeh._legacy_charts import Bar, output_file, show from bokeh.sampledata.olympics2014 import data df = pd.io.json.json_normalize(data['data']) # filter by countries with at least one medal and sort df = df[df['medals.total'] > 0] df = df.sort("medals.total", ascending=False) # get the countries and we group the data by medal type countries = df.abbr.values.tolist() gold = df['medals.gold'].astype(float).values silver = df['medals.silver'].astype(float).values bronze = df['medals.bronze'].astype(float).values # build a dict containing the grouped data medals = OrderedDict(bronze=bronze, silver=silver, gold=gold) # any of the following commented are also alid Bar inputs #medals = pd.DataFrame(medals) #medals = list(medals.values()) output_file("stacked_bar.html") bar = Bar(medals, countries, title="Stacked bars", stacked=True) show(bar)
from collections import OrderedDict from bokeh._legacy_charts import Area, show, output_file # create some example data xyvalues = OrderedDict( python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111], pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130], jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160], ) output_file(filename="area.html") area = Area( xyvalues, title="Responsive Area Chart", xlabel='time', ylabel='memory', stacked=True, legend="top_left", responsive=True ) show(area)
from collections import OrderedDict from bokeh._legacy_charts import Area, show, output_file # create some example data xyvalues = OrderedDict( python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111], pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130], jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160], ) output_file(filename="area.html") area = Area(xyvalues, title="Responsive Area Chart", xlabel='time', ylabel='memory', stacked=True, legend="top_left", responsive=True) show(area)
from bokeh._legacy_charts import Horizon, output_file, show # read in some stock data from the Yahoo Finance API AAPL = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=AAPL&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) MSFT = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=MSFT&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) IBM = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=IBM&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) xyvalues = OrderedDict( AAPL=AAPL['Adj Close'], Date=AAPL['Date'], MSFT=MSFT['Adj Close'], IBM=IBM['Adj Close'], ) output_file("horizon.html") hp = Horizon( xyvalues, index='Date', title="horizon plot using stock inputs", width=800, height=300 ) show(hp)
from collections import OrderedDict from bokeh._legacy_charts import Step, show, output_file xyvalues = OrderedDict( python=[2, 3, 7, 5, 26, 81, 44, 93, 94, 105, 66, 67, 90, 83], pypy=[12, 20, 47, 15, 126, 121, 144, 333, 354, 225, 276, 287, 270, 230], jython=[22, 43, 70, 75, 76, 101, 114, 123, 194, 215, 201, 227, 139, 160], ) # any of the following commented are also valid Step inputs #xyvalues = pd.DataFrame(xyvalues) #xyvalues = list(xyvalues.values()) #xyvalues = np.array(list(xyvalues.values())) output_file("steps.html", title="line.py example") chart = Step(xyvalues, title="Steps", ylabel='measures', legend='top_left') show(chart)
parse_dates=['Date']) xyvalues = OrderedDict( AAPL=AAPL['Adj Close'], Date=AAPL['Date'], MSFT=MSFT['Adj Close'], IBM=IBM['Adj Close'], ) # any of the following commented are valid Bar inputs #xyvalues = pd.DataFrame(xyvalues) #lindex = xyvalues.pop('Date') #lxyvalues = list(xyvalues.values()) #lxyvalues = np.array(xyvalues.values()) TOOLS="resize,pan,wheel_zoom,box_zoom,reset,previewsave" output_file("stocks_timeseries.html") ts = TimeSeries( xyvalues, index='Date', legend=True, title="Timeseries", tools=TOOLS, ylabel='Stock Prices') # usage with iterable index #ts = TimeSeries( # lxyvalues, index=lindex, # title="timeseries, pd_input", ylabel='Stock Prices') show(ts)
df2 = df.set_index(df[df.columns[0]].astype(str)) df2.drop(df.columns[0], axis=1, inplace=True) df3 = df2.transpose() # bokeh magic hm1 = HeatMap( df3, palette=palette, title="categorical heatmap, pd_input", height=400, width=1000 ) hm_data = df3.values.T hm2 = HeatMap( hm_data, palette=palette, title="Unemployment (Array)", xlabel='Years since 1948', ylabel='Months', height=400, width=1000 ) simple_df = pd.DataFrame( {'apples':[4,5,8,12,4], 'pears':[6,5,4,8,7], 'bananas':[1,2,4,8,12]}, index=['2009', '2010', '2011', '2012', '2013'] ) hm3 = HeatMap( simple_df, palette=palette, title="Fruit comsumption per year", height=400, width=1000 ) output_file("heatmap.html") show(vplot(hm1, hm2, hm3))
from bokeh._legacy_charts import Horizon, output_file, show # read in some stock data from the Yahoo Finance API AAPL = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=AAPL&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) MSFT = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=MSFT&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) IBM = pd.read_csv( "http://ichart.yahoo.com/table.csv?s=IBM&a=0&b=1&c=2000&d=0&e=1&f=2010", parse_dates=['Date']) xyvalues = OrderedDict( AAPL=AAPL['Adj Close'], Date=AAPL['Date'], MSFT=MSFT['Adj Close'], IBM=IBM['Adj Close'], ) output_file("horizon.html") hp = Horizon(xyvalues, index='Date', title="horizon plot using stock inputs", width=800, height=300) show(hp)