예제 #1
0
def heat_mapping():
	
	data = {'fruit': ['apples']*1 + ['bananas']*3 + ['pears']*3, 'fruit_count': [4, 5, 8, 1, 2, 4, 6, 5, 4], 'sample': [1, 2, 3]*3}
	hm = HeatMap(data, x='fruit', y='sample', values='fruit_count', title='Fruits', stat=None)
	output_file('heatmap.html')
	curdoc().add_root(hm)
	show(hm)
예제 #2
0
def plot_occupancy(h5_file_name):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        hit_data = in_file_h5.root.hit_data[:]

        #H, _, _ = np.histogram2d(hit_data['col'], hit_data['row'], bins = (range(65), range(65)))
        #grid = np.indices(H.shape)
        #data = {'column': np.ravel(grid[0]),
        #        'row': np.ravel(grid[1]),
        #        'value': np.ravel(H)
        #       }
        #col = np.ravel(grid[0])
        #row = np.ravel(grid[1])
        #value = np.ravel(H)
        
        hits = hit_data['col'].astype(np.uint16)
        hits = hits * 64
        hits = hits + hit_data['row']
        value = np.bincount(hits)
        value = np.pad(value, (0, 64*64 - value.shape[0]), 'constant')
       
        indices = np.indices(value.shape)
        col = indices[0] / 64
        row = indices[0] % 64
        
        data = {'column': col,
                'row': row,
                'value': value
               }
                
        hm = HeatMap(data, x='column', y='row', values='value', legend='top_right', title='Occupancy', palette=RdYlGn6[::-1], stat=None)
        
    return hm, value.reshape((64, 64))
예제 #3
0
def hotmap(datetime, room, query):
    """Generates a heatmap bokeh model"""

    #IMPORTANT: this query returns M-F values

    # get a df with date and count values, for a given room and date
    week_counts = pd.read_sql_query(query.format(date=datetime, room=room),
                                    connectDB())

    headcount = list(week_counts['count'])
    headcount = [linear_predictor(x)
                 for x in headcount]  # predict on all supplied values

    bins = list(week_counts['count'])
    # bins = [tertiary_classifier(x) for x in bins] # predict on all supplied values
    tert_dictionary = {
        'Empty': 0,
        'Medium': 0.5,
        'High': 1
    }  # map to int as only ints can go in heatmap
    # bins = [tert_dictionary[x] for x in bins] # map with listcomp

    # 5 * 9 = 45, so all elements need to have 45 values. Days and hours are just multipled out.
    data = {
        'days':
        ['fri'] * 9 + ['thu'] * 9 + ['wed'] * 9 + ['tue'] * 9 + ['mon'] * 9,
        'occupancy': headcount,
        'hours': ['9', '10', '11', '12', '13', '14', '15', '16', '17'] * 5
    }

    week_counts['headcount'] = week_counts['count'].apply(linear_predictor)
    week_counts['bins'] = week_counts['count'].apply(tertiary_classifier)

    source = ColumnDataSource(ColumnDataSource.from_df(week_counts))

    # hover = HoverTool()
    #
    # tooltips = [("headcount", "@headcount")]
    #
    # tools = [hover]

    # colors = ['#1abc9c', '#ec583a', '#474e5d'] # set colors; currently not shading on continuous features

    hm = HeatMap(data,
                 x='hours',
                 y='days',
                 values='occupancy',
                 title='Occupancy in room over the week'.format(room),
                 stat=None,
                 palette=palette,
                 tools=None,
                 hover_tool=True)

    legend = Legend(location=(0, -30))

    hm.add_layout(legend, 'right')

    all_plots = gridplot([[hm]])

    return all_plots
예제 #4
0
def create_heatmap(df):

    products=['Debit Card',
              'Personal Credit Card',
              'Business Credit Card',
              'Home Mortgage Loan',
              'Auto Loan',
              'Brokerage Account',
              'Roth IRA',
              '401k',
              'Home Insurance',
              'Automobile Insurance',
              'Medical Insurance',
              'Life Insurance',
              'Cell Phone',
              'Landline'
              ]

    def rename_columns(df):
        df = df.copy()
        df.columns = [products[i] for i in df.columns]
        return df

    # create an artificial dataset with 3 clusters
    X, Y = make_classification(n_samples=100, n_classes=4, n_features=12, n_redundant=0, n_informative=12,
                               scale=1000, n_clusters_per_class=1)
    df2 = pd.DataFrame(X)
    # ensure all values are positive (this is needed for our customer 360 use-case)
    df2 = df2.abs()
    # rename X columns
    df2 = rename_columns(df2)
    # and add the Y
    df2['y'] = Y
    #df
    # split df into cluster groups
    grouped = df2.groupby(['y'], sort=True)

    # compute sums for every column in every group
    sums = grouped.sum()

    score = []
    for x in sums.apply(tuple):
        score.extend(x)

    data=dict(
        persona=list(sums.index) * len(sums.columns),
        product=[item for item in list(sums.columns) for i in range(len(sums.index))],
        score=score
    )

    hm = HeatMap(data, x='product', y='persona', values='score', title='Customer Profiles', xlabel='Product', ylabel='Persona', legend=False, stat=None,  tools=["save"], height=400, width=900, toolbar_location=None)
    hm.yaxis.ticker=FixedTicker(ticks=[0,1,2,3])
    hm_source = ColumnDataSource(data=sums)

    hm_data_table = DataTable(
        source=hm_source,
        columns=[TableColumn(field=c, title=c) for c in sums.columns], width=900, height=150)

    return hm
def prepare_and_draw_matrix(dh_mat2, heading_list, disc_list, outfile):
    
    totals = {}
    for d in disc_list:
        total = 0
        for h in heading_list:
            if( dh_mat2[h].get(d, None) is not None):
                total += dh_mat2[h][d]
        totals[d] = total 
    
    section = []
    d_type = []
    percent = []
    for d in disc_list:
        for h in heading_list:
            if( dh_mat2[h].get(d, None) is None):
                section.append(h)
                d_type.append(d)
                percent.append(0.0)
            else : 
                section.append(h)
                d_type.append(d)
                percent.append(100.0 * dh_mat2[h][d] / totals[d])
        
    data = {'Section': section,
            'Discourse Type': d_type,
             'Percentage': percent
            }
    
    color = ColorAttr(bin=True, palette=gray(6), sort=True, ascending=False)

    hm = HeatMap(data, x='Discourse Type', y='Section', values='Percentage',
                stat=None, plot_height=260, legend=False, color=color)
    
    output_file(outfile+'1.html', mode='cdn', root_dir=None)
    save(hm)

    hm1 = HeatMap(data, x='Discourse Type', y='Section', values='Percentage',
                stat=None, plot_height=260, legend=True, color=color)
    
    output_file(outfile+'2.html', mode='cdn', root_dir=None)
    save(hm1)

     
    '''
예제 #6
0
    def plot_heatmap(self, identifier, enso, chart, average_table):
        chart_title = chart + " Heatmap"
        removed_total = average_table
        if (identifier != "both"):
            removed_total = np.delete(average_table, self.NUM_SOURCES, 1)
        if (identifier == "both"):
            removed_total = np.delete(average_table, self.NUM_REGIONS, 1)
        formatted_data = None
        height = 900
        x_label = identifier
        y_label = "Source"
        filename = identifier
        if (identifier == "regions"):
            formatted_data = pandas.DataFrame(data=removed_total,
                                              index=self.basic_sources,
                                              columns=self.regions)
            height = 600
            width = 1400
            x_label = "Regions"
        if (identifier == "species"):
            formatted_data = pandas.DataFrame(data=removed_total,
                                              index=self.species,
                                              columns=self.basic_sources)
            width = 600
            x_label = "Species"
        if (identifier == "both"):
            formatted_data = pandas.DataFrame(data=removed_total,
                                              index=self.species,
                                              columns=self.regions)
            height = 900
            width = 1400
            x_label = "Regions"
            y_label = "Species"
            filename += "_combined"
        palette = red_palette[::
                              -1]  # Reverse the color order so dark red is highest
        if (enso):
            palette = red_blue_palette
            filename += "_ENSO"
        output_file("plots/tables/" + chart + "/plots/" + filename +
                    "_heatmap.html",
                    title=chart_title)

        p = HeatMap(formatted_data,
                    width=width,
                    height=height,
                    title=chart_title,
                    xlabel=x_label,
                    ylabel="Source",
                    palette=palette)
        save(p)
예제 #7
0
    def heat_mapping(self,
                     title="heatmap",
                     outfile="blah_output.html",
                     rows=50):
        data = self.process_heat(rows=rows)

        hm = HeatMap(data,
                     title="Heatmap",
                     x="x",
                     y="y",
                     values="count",
                     stat=None)
        output_file(outfile)
        curdoc().add_root(hm)
        show(hm)
예제 #8
0
def heatmap(heatMapDF,
            xlabel,
            ylabel,
            value_label,
            title="heatmap",
            palette=None,
            width=500,
            height=500,
            **kwargs):
    from bokeh.charts import HeatMap
    if not palette:
        from bokeh.palettes import RdBu11 as palette_tmpl
        palette = palette_tmpl
    hm = HeatMap(heatMapDF,
                 x=xlabel,
                 y=ylabel,
                 values=value_label,
                 title=title,
                 height=height,
                 width=width,
                 palette=palette,
                 **kwargs)
    return hm
예제 #9
0
def plot_occupancy(h5_file_name):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        hit_data = in_file_h5.root.hit_data[:]

        hits = hit_data['col'].astype(np.uint16)
        hits = hits * 64
        hits = hits + hit_data['row']
        value = np.bincount(hits)
        value = np.pad(value, (0, 64 * 64 - value.shape[0]), 'constant')

        indices = np.indices(value.shape)
        col = indices[0] / 64
        row = indices[0] % 64

        data = {'column': col,
                'row': row,
                'value': value
                }

        hm = HeatMap(data, x='column', y='row', values='value', legend='top_right', title='Occupancy',
                     palette=RdYlGn6[::-1], stat=None)

    return hm, value.reshape((64, 64))
예제 #10
0
    def heatmap(self,
                dataframe,
                y=None,
                x=None,
                values=None,
                width=None,
                height=None,
                palette=None,
                max_color=None,
                min_color=None,
                mid_color=None,
                title='Heatmap',
                xaxis_label=None,
                yaxis_label=None):

        palette = self.__default_options__.get(
            'palette', None) if palette is None else palette
        width = self.__default_options__.get('width',
                                             None) if width is None else width

        width, height = self._width_height(width, height)

        heatmap = HeatMap(dataframe,
                          x=x,
                          y=y,
                          values=values,
                          width=width,
                          height=height,
                          palette=palette,
                          title=title)
        if xaxis_label:
            heatmap._xaxis.axis_label = xaxis_label
        if yaxis_label:
            heatmap._yaxis.axis_label = yaxis_label

        return heatmap
예제 #11
0
fruits = {
    'fruit': [
        'apples', 'apples', 'apples', 'apples', 'apples', 'pears', 'pears',
        'pears', 'pears', 'pears', 'bananas', 'bananas', 'bananas', 'bananas',
        'bananas'
    ],
    'fruit_count': [4, 5, 8, 12, 4, 6, 5, 4, 8, 7, 1, 2, 4, 8, 12],
    'year': [
        2009, 2010, 2011, 2012, 2013, 2009, 2010, 2011, 2012, 2013, 2009, 2010,
        2011, 2012, 2013
    ]
}
fruits['year'] = [str(yr) for yr in fruits['year']]

hm1 = HeatMap(autompg, x=bins('mpg'), y=bins('displ'))

hm2 = HeatMap(autompg,
              x=bins('mpg'),
              y=bins('displ'),
              values='cyl',
              stat='mean')

hm3 = HeatMap(autompg,
              x=bins('mpg'),
              y=bins('displ', bins=15),
              values='cyl',
              stat='mean')

hm4 = HeatMap(autompg, x=bins('mpg'), y='cyl', values='displ', stat='mean')
예제 #12
0
from bokeh.charts import HeatMap, output_file, show
import pandas as pd

df.reset_index(inplace=True)

hm = HeatMap(df, y='from', x='to', values='christina', title='TM', stat=None)

output_file('heatmap.html', mode='inline')
show(hm)
예제 #13
0
from collections import OrderedDict

from bokeh.sampledata.unemployment1948 import data
from bokeh.charts import HeatMap

# pandas magic
df = data[data.columns[:-2]]
df2 = df.set_index(df[df.columns[0]].astype(str))
df2.drop(df.columns[0], axis=1, inplace=True)
df3 = df2.transpose()

cols = df3.columns.tolist()
index = df3.index.tolist()

#prepare some inputs
to_odict = lambda v: OrderedDict((kk, v[kk]) for kk in index)

# Create an ordered dict (or ordered dicts) with the data from the DataFrame
datadict = df3.to_dict()
data = OrderedDict(sorted((k, to_odict(v)) for k, v in datadict.items()))

# any of the following commented line is a valid HeatMap input
#data = df3
#data = df3.values.T
#data = list(df3.values.T)

hm = HeatMap(data,
             title="categorical heatmap, pd_input",
             filename="cat_heatmap.html")
hm.width(1000).height(400).show()
예제 #14
0
	df_matrix =  pd.DataFrame(matrix)
	return df_matrix

prem_last = calcMatrixHeatMap(conversion_close)
prem_7day = calcMatrixHeatMap(rolling_7day)
prem_30day = calcMatrixHeatMap(rolling_30day)

from bokeh.layouts import row
from bokeh.plotting import figure, show, output_file
from bokeh.charts import HeatMap, bins, output_file, show
from bokeh.palettes import RdBu, magma
from bokeh.models import ColumnDataSource, LabelSet, Label

output_file("ccy-premium.html", title="BTC premia")

hm1 = HeatMap(prem_last, x='from', y='to', values='diff', title='Premia Last Closing (USD). diff = from - to, % = (from - to)/to', stat=None, palette=['green', 'gray', 'red'], legend=False)
source1 = ColumnDataSource(data=prem_last)
labels1a = LabelSet(x='from', y='to', text='formatted', level='glyph', x_offset=-15, y_offset=-10, render_mode='canvas', source=source1)
labels1b = LabelSet(x='from', y='to', text='percent', level='glyph', x_offset=-15, y_offset=-30, render_mode='canvas', source=source1)
hm1.add_layout(labels1a)
hm1.add_layout(labels1b)

hm2 = HeatMap(prem_7day, x='from', y='to', values='diff', title='Premia 7 days average (USD)', stat=None, palette=['green', 'gray', 'red'], legend=False)
source2 = ColumnDataSource(data=prem_7day)
labels2a = LabelSet(x='from', y='to', text='formatted', level='glyph', x_offset=-15, y_offset=-10, render_mode='canvas', source=source2)
labels2b = LabelSet(x='from', y='to', text='percent', level='glyph', x_offset=-15, y_offset=-30, render_mode='canvas', source=source2)
hm2.add_layout(labels2a)
hm2.add_layout(labels2b)

hm3 = HeatMap(prem_30day, x='from', y='to', values='diff', title='Premia 30 days average (USD)', stat=None, palette=['green', 'gray', 'red'], legend=False)
source3 = ColumnDataSource(data=prem_30day)
## evaluate z
z_normal = np.load(os.path.join(DSC_DIR,
                                'z_' + NORMAL_NAME))[0].reshape(134 * 32, 64)
z_simple = np.load(os.path.join(DSC_DIR,
                                'z_' + SIMPLE_NAME))[0].reshape(134 * 32, 64)

select_0 = 100
output_file('heat_map_dsc.html')
sq_diff = ((z_normal - z_simple)[:select_0]**2).flatten()
y = np.array([list(range(z_normal.shape[1]))] * select_0).flatten()
x = np.array([[i] * z_normal.shape[1] for i in range(select_0)]).flatten()
pl = HeatMap({
    'values': sq_diff,
    'example': x,
    'z[i]': y
},
             y='z[i]',
             x='example',
             values='values',
             stat=None,
             palette=palettes.Spectral9)
pl.title.text_font_size = '18pt'
pl.legend.location = 'bottom_right'
pl.legend.label_text_font_size = '12pt'
pl.xaxis.major_label_text_font_size = '14pt'
pl.yaxis.major_label_text_font_size = '14pt'
pl.xaxis.axis_label_text_font_size = '14pt'
pl.yaxis.axis_label_text_font_size = '14pt'
show(pl)
output_file('normal_z_heat_map_dsc.html')
pl = HeatMap({
    'values': z_normal[:select_0].flatten(),
예제 #16
0
#importing modules
import bokeh

import pandas as pd
import numpy as np

from bokeh.charts import Scatter, output_file, save
from bokeh.charts import HeatMap, output_file, save
from bokeh.layouts import gridplot
from bokeh.plotting import figure, save, output_file

#read file
df = pd.read_csv('file.csv')

#Plots a heatmap
p = HeatMap(df, x='Date', y='Temperature', values=None, stat='count', xgrid=False, ygrid=False, hover_tool=True, hover_text='Temperature', plot_width=2000, plot_height=1000)

output_file('HeatMap.html')

#Saves graph
save(p)

#box = BoxPlot(df, values='Temperature', label='Date', title="Temperature Date Box Plot", plot_width=400)

#Creates a Scatter Plot
v = Scatter(df, x='Date', y='Temperature', color='red', title="Date vs. Temperature", legend='top_right', xlabel="Date", ylabel="Temperature", plot_width=2000, plot_height=1000)

output_file('Scatter.html')

#Saves Graph as a html file
save(v)
예제 #17
0
fruits = {
    'fruit': [
        'apples', 'apples', 'apples', 'apples', 'apples', 'pears', 'pears',
        'pears', 'pears', 'pears', 'bananas', 'bananas', 'bananas', 'bananas',
        'bananas'
    ],
    'fruit_count': [4, 5, 8, 12, 4, 6, 5, 4, 8, 7, 1, 2, 4, 8, 12],
    'year': [
        '2009', '2010', '2011', '2012', '2013', '2009', '2010', '2011', '2012',
        '2013', '2009', '2010', '2011', '2012', '2013'
    ]
}

plot_cat_unbounded = HeatMap(fruits,
                             y='year',
                             x='fruit',
                             values='fruit_count',
                             stat=None,
                             title="Heatmap (unbounded)")

plot_cat_autobounded = HeatMap(fruits,
                               y='year',
                               x='fruit',
                               values='fruit_count',
                               stat=None,
                               title="Heatmap (autobounded)")
###### -- ranges set here -- ########
plot_cat_autobounded.x_range.bounds = 'auto'
plot_cat_autobounded.y_range.bounds = 'auto'
###### -- end -- ########

plot_cat_bounded = HeatMap(
예제 #18
0
import pandas as pd

from bokeh.charts import HeatMap, output_file, show, vplot
from bokeh.palettes import Blues9 as palette
from bokeh.sampledata.unemployment1948 import data

# pandas magic
df = data[data.columns[:-2]]
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],
예제 #19
0
df_hmp = (pd.merge(agg.reset_index(), products,
                   on='Producto_ID', how='left').groupby([
                       'Semana', 'short_name'
                   ])['Demanda_uni_equil_sum', 'Venta_uni_hoy_sum',
                      'Dev_uni_proxima_sum',
                      'Dev_uni_proxima_count'].sum().reset_index())
df_hmp.head()
df_hmp['log1p_Demanda_uni_equil_sum'] = np.log1p(df_hmp.Demanda_uni_equil_sum)
g = sns.FacetGrid(df_hmp, row='Semana')
g = g.map(sns.distplot, 'log1p_Demanda_uni_equil_sum')
from bokeh.charts import HeatMap
from bokeh.plotting import vplot

heatmaps = []
for i in df.Q.cat.categories.values:
    hm = HeatMap(
        df_hmp[df_hmp.short_name.isin(df[df.Q == i].index.values)],
        x='short_name',
        y='Semana',
        values='Demanda_uni_equil_sum',
        hover_tool=True,
        title='Products with summary demand ' + str(i),
        xgrid=False,
        stat='sum',
        plot_width=950,
        plot_height=400,
        tools='hover, box_zoom, resize, save, wheel_zoom, reset',
    )
    heatmaps.append(hm)
show(vplot(*heatmaps))
예제 #20
0
from bokeh.models import ColumnDataSource, LabelSet, Label

output_file("index.html", title="BTC premia")

dateToDisplay = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

custompalette = [
    '#00814c', '#1ebd7c', '#26cc88', '#3ee09e', '#71ffc5', 'grey', '#fcffc8',
    '#ffeb66', '#ffca49', '#ff9600', '#d00031'
]

hm1 = HeatMap(
    prem_last,
    x='from',
    y='to',
    values='diff',
    title=dateToDisplay +
    ' Premia Last Closing (USD). diff = from - to, % = (from - to)/to',
    stat=None,
    palette=custompalette,
    legend=False)
source1 = ColumnDataSource(data=prem_last)
#labels1a = LabelSet(x='from', y='to', text='formatted', level='glyph', x_offset=-10, y_offset=-10, render_mode='canvas', source=source1, text_font_size='9pt')
labels1b = LabelSet(x='from',
                    y='to',
                    text='percent',
                    level='glyph',
                    x_offset=-10,
                    y_offset=-10,
                    render_mode='canvas',
                    source=source1,
                    text_font_size='9pt')
예제 #21
0
파일: hm13.py 프로젝트: danbikle/tsds
import pandas as pd

from bokeh.charts import HeatMap, bins, output_file, show
from bokeh.layouts import column, gridplot
from bokeh.palettes import RdYlGn6, RdYlGn9
from bokeh.sampledata.unemployment1948 import data

# setup data sources
del data['Annual']
data['Year'] = data['Year'].astype(str)
unempl = pd.melt(data, var_name='Month', value_name='Unemployment', id_vars=['Year'])

fruits = {'fruit': ['apples', 'apples', 'apples', 'apples', 'apples',
                    'pears', 'pears', 'pears', 'pears', 'pears',
                    'bananas', 'bananas', 'bananas', 'bananas', 'bananas'],
          'fruit_count': [4, 5, 8, 12, 4, 6, 5, 4, 8, 7, 1, 2, 4, 8, 12],
          'year': [2009, 2010, 2011, 2012, 2013, 2009, 2010, 2011, 2012, 2013, 2009, 2010,
                   2011, 2012, 2013]}
fruits['year'] = [str(yr) for yr in fruits['year']]

hm9 = HeatMap(fruits, y='year', x='fruit', values='fruit_count', stat=None)

hm10 = HeatMap(unempl, x='Year', y='Month', values='Unemployment', stat=None,
              sort_dim={'x': False}, width=900, plot_height=500)

output_file("hm13.html", title="Bokeh heatmap example (hm13.py)")

show(column(hm9,hm10))

df = pd.DataFrame(value_mt)
topic_words = pd.DataFrame(corpus.keys())
df2 = df.transpose().set_index(topic_words[topic_words.columns[0]])
df3 = df2.transpose()
topic_label = pd.DataFrame(['topic_' + str(i) for i in range(topic_number)])
df3 = df3.set_index(topic_label[topic_label.columns[0]])

html_path = folder_name + str(topic_number) + '_topic_Weight_Management.html'
output_file(html_path,
            title=str(topic_number) + '_topic_Weight_Management.html')

palette = palette[::
                  -1]  # Reverse the color order so dark red is highest unemployment
hm = HeatMap(df3,
             title=str(topic_number) + '_topic_Weight_Management.html',
             tools="reset,resize",
             width=1300,
             height=700,
             palette=palette)

show(hm)

#==============================================================================
# generate all urls under each topic
#==============================================================================

tem_list = []
for i in range(len(doc_list)):
    tem = '{},{}'.format(titles[i], fin_sum[i]).split(',')
    tem[1] = float(tem[1])
    tem_list.append(tem)
tem_list = sorted(tem_list, key=lambda res: res[1], reverse=False)
from bokeh.layouts import row
from bokeh.plotting import figure, show, output_file
from bokeh.charts import HeatMap, bins, output_file, show
from bokeh.palettes import RdBu, magma
from bokeh.models import ColumnDataSource, LabelSet, Label

output_file("ccy-premium.html", title="BTC premia")

dateToDisplay = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

hm1 = HeatMap(
    prem_last,
    x='from',
    y='to',
    values='diff',
    title=dateToDisplay +
    ' Premia Last Minute Closing (USD). diff = from - to, % = (from - to)/to',
    stat=None,
    palette=['green', 'gray', 'red'],
    legend=False)
source1 = ColumnDataSource(data=prem_last)
labels1a = LabelSet(x='from',
                    y='to',
                    text='formatted',
                    level='glyph',
                    x_offset=-15,
                    y_offset=-10,
                    render_mode='canvas',
                    source=source1)
labels1b = LabelSet(x='from',
                    y='to',
예제 #24
0
    def process_file(self, file_path):
        """
        Process the file given.  This read from the file
        and add it to the codec.  The codec will then decode
        the data and pass it to the UDP port.
        """
        # Check if the file exist
        if os.path.exists(file_path):

            logger.info("Open file: " + file_path)

            # Open the file
            f = open(file_path, "rb")

            # Add the data from the file to the codec
            data = f.read(4096)
            while len(data) > 0:
                # Add data to codec
                self.codec.add(data)

                # Read next block from the file
                data = f.read(4096)

            # Close the file
            f.close()

            # Display the Heatmap and save it to HTML file
            output_file('test.html')

            hover = HoverTool(tooltips=[
                ("index", "$index"),
                ("(x,y)", "($x, $y)"),
                ("desc", "@desc"),
            ])

            TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom"

            hm = HeatMap(
                self.df_mag_ens,
                x='ens',
                y='bin',
                values='mag',
                stat=None,
                sort_dim={'x': False},
                width=1000,
                spacing_ratio=0.9,
                tools=TOOLS,
                toolbar_location="above",  # Move toolbar to top
                toolbar_sticky=False)  # Make toolbar not to close to plot

            # Set min and max axis and invert axis
            xmin = self.df_mag_ens['ens'].min()
            xmax = self.df_mag_ens['ens'].max()
            ymax = self.df_mag_ens['bin'].min()  # Swap Min and Max for y axis
            ymin = self.df_mag_ens['bin'].max()  # Swap Min and Max for y axis
            hm.x_range = Range1d(
                xmin, xmax)  # Set the min and max, so no gaps on edges
            hm.y_range = Range1d(
                ymin, ymax)  # Set the min and max, so no gaps on edges
            show(hm)

            while True:
                input("Press enter to continue")
                break

        else:
            logger.error("File does not exist")
예제 #25
0
from bokeh.layouts import column, gridplot
from bokeh.palettes import RdYlGn6, RdYlGn9
from bokeh.sampledata.autompg import autompg
from bokeh.sampledata.unemployment1948 import data
# setup data sources
del data['Annual']
print(type(data))

data['Year'] = data['Year'].astype(str)
unempl = pd.melt(data,
                 var_name='Month',
                 value_name='Unemployment',
                 id_vars=['Year'])

jobs = {
    'time_process': [20161104, 20161105, 20161106],
    'job_status': [0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1],
    'job_id': [72, 74, 4251, 4252, 4253]
}
jobs['job_id'] = [str(id) for id in jobs['job_id']]

hmap = HeatMap(jobs,
               y='job_id',
               x='time_process',
               values='job_status',
               stat=None)

output_file("heatmap.html", title="heatmap.py example")

show(column(gridplot(hmap, ncols=2, plot_width=400, plot_height=400), ))
예제 #26
0
#               palette=RdYlGn6)

# hm7 = HeatMap(autompg, x=bins('mpg'), y=bins('displ'), stat='mean', values='cyl',
#               palette=RdYlGn9)

# hm8 = HeatMap(autompg, x=bins('mpg'), y=bins('displ'), values='cyl',
#               stat='mean', legend='top_right')

# hm9 = HeatMap(fruits, y='year', x='fruit', values='fruit_count', stat=None)

# hm10 = HeatMap(unempl, x='Year', y='Month', values='Unemployment', stat=None,
#               sort_dim={'x': False}, width=900, plot_height=500)

TOOLS = [BoxSelectTool(), HoverTool()]

hm11 = HeatMap(test, x='region', y='area', values='data', legend=False, stat=None, palette=GnRd9, width = 500, plot_height=500, title="Actlab Region Detection Test", tools=TOOLS)
hm12 = Bar(data_bar, values='dist', label='region', legend=False, title='Error Distance for Respective Regions', width = 800, plot_height = 500)
hm13 = BoxPlot(data_bar, values='dist', label='region', legend=False, title='Error Distance Boxplot', width = 300, plot_height=300)
#hm11.legend.location = 'right'
# data1 = [int(x) for x in data]
# print data1
# hover = HoverTool(tooltips=[
#   ("error", "@data1")])
# hm11.add_tools(hover)  
hm11.add_layout(labels)
hm11.add_layout(labels_dev)
hm12.add_layout(label_reg)
# output_file("heatmap.html")
output_file("Bar.html")
hm11.axis.visible = False
# show(hm11)
예제 #27
0
from bokeh.charts import HeatMap, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
data = {'fruit': ['apples']*3 + ['bananas']*3 + ['pears']*3,
        'fruit_count': [4, 5, 8, 1, 2, 4, 6, 5, 4],
        'sample': [1, 2, 3]*3}

hm = HeatMap(data, x='fruit', y='sample', values='fruit_count',
             title='Fruits', stat=None)

output_file('heatmap.html')
show(hm)
예제 #28
0
from bokeh.charts import HeatMap, output_file, show

import pandas as pd

output_file('heatmap.html')

df = pd.DataFrame(
        dict(
            apples=[4, 5, 8],
            bananas=[1, 2, 4],
            pears=[6, 5, 4],
        ),
        index=['2012', '2013', '2014']
    )

p = HeatMap(df, title='Fruits')

show(p)
예제 #29
0
파일: cat_heatmap.py 프로젝트: tengqu/bokeh
from bokeh.charts import HeatMap, output_file, show
from bokeh.sampledata.unemployment1948 import data

# pandas magic
df = data[data.columns[:-2]]
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")

hm = HeatMap(df3, title="categorical heatmap", width=800)

show(hm)
예제 #30
0
def bokeh_heatmap(index=['Date', 'Representative']):
    #return three retention matrices
    percent_MRR, actual_MRR, contract_MRR = pivot_tables(combo=generate_data(
        n_sample=100, periods=30),
                                                         index=index)

    #reformat data to column sparse matrix and place into dictionary
    x = []
    y = []
    vals = []
    [(y.append(i[0]), x.append(i[1]), vals.append(v))
     for i, v in np.ndenumerate(percent_MRR)]
    data = {'x': x, 'y': y, 'vals': vals}

    #heatmap instantiate
    hm = HeatMap(data=data,
                 x='x',
                 y='y',
                 values='vals',
                 stat=None,
                 title='Revenue Retention by {}'.format(','.join(index)),
                 ygrid=True,
                 xgrid=True,
                 xlabel='months',
                 ylabel='contract start',
                 yscale='categorical',
                 palette=brewer['RdYlGn'][11],
                 title_text_font_size='20pt')
    #add value labels to heat map
    # create formatted column of values for annotation labels
    data['labels'] = [
        '{:.0%}'.format(round(i, 2)) if i >= 0 else '' for i in data['vals']
    ]
    #dropping vals which are not json compliant
    del data['vals']
    source = ColumnDataSource(data=data)
    labels = LabelSet(x='x',
                      y='y',
                      text='labels',
                      level='glyph',
                      x_offset=-2,
                      y_offset=-4,
                      source=source,
                      render_mode='canvas',
                      text_font_size='7pt',
                      text_color='white')
    hm.add_layout(labels)

    # customize y-axis text

    # new_index=actual_MRR.sum(axis=1).reset_index()
    # new_index.rename(columns={0: 'Actual MRR'}, inplace=True)
    # new_index['Contract MRR']=contract_MRR.sum(axis=1).reset_index()[0]
    y_label_dict = {}

    for index, groups in enumerate(list(percent_MRR.index)):
        y_label_dict[index] = '-'.join(groups)
    #reverse y-axis order
    hm.y_range.start = max(y_label_dict.keys())
    hm.y_range.end = min(y_label_dict.keys())
    hm.x_range = Range1d(0, 12)
    #generate javascript code to reformat y-axis
    hm.yaxis.formatter = FuncTickFormatter(code="""var labels = {};
                                                 return labels[tick];
                                                 """.format(y_label_dict))
    # fix ticks to display all values
    hm.yaxis[0].ticker = FixedTicker(ticks=list(y_label_dict.keys()))

    total_contract_mrr = contract_MRR.sum(axis=1)
    total_actual_mrr = actual_MRR.sum(axis=1)
    yaxis2_text = pd.concat([total_actual_mrr, total_contract_mrr], axis=1)

    yaxis2_text.reset_index(drop=True, inplace=True)
    yaxis2_text.columns = ['Actual MRR', 'Contract MRR']
    yaxis2_text['text'] = yaxis2_text.apply(
        lambda row: '{:,.0f}/{:,.0f} \t ({:.0%})'.format(
            row['Actual MRR'], row['Contract MRR'], row['Actual MRR'] / row[
                'Contract MRR']),
        axis=1)
    yaxis2_text = yaxis2_text['text'].to_dict()

    #add right hand y-axis for additional information
    top = max(yaxis2_text.keys())
    bottom = min(yaxis2_text.keys())
    print(top, bottom)

    hm.extra_y_ranges = {'mrr': Range1d(top, bottom)}

    hm.add_layout(LinearAxis(y_range_name="mrr"), 'right')

    hm.yaxis[1].formatter = FuncTickFormatter(code="""var labels = {};
                                                 return labels[tick];
                                                 """.format(yaxis2_text))
    hm.yaxis[1].ticker = FixedTicker(ticks=list(yaxis2_text.keys()))
    hm.yaxis[1].axis_label = 'Actual and Contract MRR'
    hm.yaxis[1].major_label_standoff = 30

    # #help(hm.legend)
    # legend_items=list(hm.legend)[0].items
    #

    hm.legend.location = 'bottom_right'

    # exit()
    output_file('interactive.html')
    show(hm)