示例#1
0
def donutchart(*args, **kwargs):
    #get info from submitted data
    data = kwargs.get('data', 'None')
    ids = kwargs.get('ids', 'None')
    vals = kwargs.get('vals', 'None')
    val_name = kwargs.get('val_name', 'None')
    v_name = kwargs.get('v_name', 'None')
    out_file = kwargs.get('out_file', 'None')

    if vals or data or ids or val_name == 'None':
        return "Data must be submitted"

    df = df_from_json(data)
    df = df.sort("total", ascending=False)
    df = pd.melt(df, id_vars=[ids],
                value_vars=[vals],
                value_name=val_name,
                var_name=v_name)
    d = Donut(df, label=[ids, v_name],
            values=v_name,
            text_font_size='8pt',
            hover_text='vals')

    output_file(out_file)
    save(d)
示例#2
0
def donutLsi(data):
    TOOLS = 'box_zoom,hover,crosshair,resize,reset'
    dat = {'object': 'list'}  # {'type': 'old', 'contr': -3.5}, {'type': 'cold', 'contr': -4.45}
    dat['data'] = data
    df = df_from_json(dat)
    TITLE = "LSI Topic #"+ str(data[0]['nr'])
    d = Donut(df, label='type', text_font_size='10pt', hover_text='Test', values='contr', toolbar_location="right", tools=TOOLS, title=TITLE)
    return d
示例#3
0
def load_project_funding():
    project_funding = df_from_json(json_file_path)

    # cleanup column names
    cols = project_funding.columns
    flat_cols = [col.split('.')[1] if '.' in col else col for col in cols]
    project_funding.columns = flat_cols

    # convert to dates
    project_funding['client_time'] = pd.to_datetime(project_funding['client_time'], unit='s')
    return project_funding
示例#4
0
def load_project_funding():
    project_funding = df_from_json(json_file_path)

    # cleanup column names
    cols = project_funding.columns
    flat_cols = [col.split('.')[1] if '.' in col else col for col in cols]
    project_funding.columns = flat_cols

    # convert to dates
    project_funding['client_time'] = pd.to_datetime(
        project_funding['client_time'], unit='s')
    return project_funding
示例#5
0
from bokeh.charts import Donut, show, output_file
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

import pandas as pd

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 8]
df = df.sort("total", ascending=False)
df = pd.melt(df, id_vars=['abbr'],
             value_vars=['bronze', 'silver', 'gold'],
             value_name='medal_count', var_name='medal')

# original example
d = Donut(df, label=['abbr', 'medal'], values='medal_count',
          text_font_size='8pt', hover_text='medal_count')

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

show(d)


<nav class="w3-sidebar w3-bar-block w3-animate-left w3-grey" style="display:none", id="my_sidebar">
<button class="w3-bar-item w3-button w3-xlarge" onclick="w3_close()">Close &times;</button>
<a href="#" class="w3-bar-item w3-button w3-padding-large w3-grey">
 <i class="fa fa-home w3-xxlarge">

 </i>
示例#6
0
from bokeh.charts import Donut, show, output_file
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

import pandas as pd

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 8]
df = df.sort("total", ascending=False)
df = pd.melt(df, id_vars=['abbr'],
             value_vars=['bronze', 'silver', 'gold'],
             value_name='medal_count', var_name='medal')

# original example
d = Donut(df, label=['abbr', 'medal'], values='medal_count',
          text_font_size='8pt', hover_text='medal_count')

output_file("donut.html")
show(d)
示例#7
0
                   ylabel="Horsepower",
                   legend='top_right',
                   tooltips=[('origin', "@origin")])

scatter4 = Scatter(df,
                   x='mpg',
                   y='hp',
                   color='cyl',
                   marker='origin',
                   title="x='mpg', y='hp', color='cyl', marker='origin'",
                   xlabel="Miles Per Gallon",
                   ylabel="Horsepower",
                   legend='top_right')

# Example with nested json/dict like data, which has been pre-aggregated and pivoted
df2 = df_from_json(data)
df2 = df2.sort('total', ascending=False)

df2 = df2.head(10)
df2 = pd.melt(df2, id_vars=['abbr', 'name'])

scatter5 = Scatter(df2,
                   x='value',
                   y='name',
                   color='variable',
                   title="x='value', y='name', color='variable'",
                   xlabel="Medals",
                   ylabel="Top 10 Countries",
                   legend='bottom_right')

scatter6 = Scatter(
示例#8
0
scatter2 = Scatter(
    df, x='mpg', y='hp', color='cyl', title="x='mpg', y='hp', color='cyl'",
    xlabel="Miles Per Gallon", ylabel="Horsepower", legend='top_right')

scatter3 = Scatter(
    df, x='mpg', y='hp', color='origin', title="x='mpg', y='hp', color='origin', with tooltips",
    xlabel="Miles Per Gallon", ylabel="Horsepower",
    legend='top_right', tooltips=[('origin', "@origin")])

scatter4 = Scatter(
    df, x='mpg', y='hp', color='cyl', marker='origin', title="x='mpg', y='hp', color='cyl', marker='origin'",
    xlabel="Miles Per Gallon", ylabel="Horsepower", legend='top_right')

# Example with nested json/dict like data, which has been pre-aggregated and pivoted
df2 = df_from_json(data)
df2 = df2.sort('total', ascending=False)

df2 = df2.head(10)
df2 = pd.melt(df2, id_vars=['abbr', 'name'])

scatter5 = Scatter(
    df2, x='value', y='name', color='variable', title="x='value', y='name', color='variable'",
    xlabel="Medals", ylabel="Top 10 Countries", legend='bottom_right')

scatter6 = Scatter(flowers, x=blend('petal_length', 'sepal_length', name='length'),
                   y=blend('petal_width', 'sepal_width', name='width'), color='species',
                   title='x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',
                   legend='top_right')

output_file("scatter_multi.html", title="scatter_multi.py example")
示例#9
0
wedge = {
    'data': [{
        '0': 1,
        '1': 1,
        '2': 1,
        '3': 1,
        '4': 1,
        '5': 1,
        '6': 1,
        '7': 1,
        '8': 1,
        '9': 1
    }]
}

df = df_from_json(wedge)
df = pd.melt(df,
             value_vars=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
             value_name='number',
             var_name='spectrograph')

wedge_b = Donut(df,
                plot_height=220,
                plot_width=220,
                color=source.data['color'])
wedge_r = Donut(df,
                plot_height=220,
                plot_width=220,
                color=source.data['color'])
wedge_z = Donut(df,
                plot_height=220,