Here are the examples of the python api bokeh.models.Toggle taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
0
Source : variable_cell.py
with MIT License
from evdoxiataka
with MIT License
from evdoxiataka
def _initialize_toggle_div(self):
""""
Creates the toggle headers of each variable node.
"""
for space in self.spaces:
width = self.plot[space].plot_width
height = 40
sizing_mode = self.plot[space].sizing_mode
label = self.name + " ~ " + self._data.get_var_dist(self.name)
text = """parents: %s < br>dims: %s"""%(self._data.get_var_parents(self.name), list(self._data.get_idx_dimensions(self.name)))
if sizing_mode == 'fixed':
self._toggle[space] = Toggle(label = label, active = False,
width = width, height = height, sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text,
width = width, height = height, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
elif sizing_mode == 'scale_width' or sizing_mode == 'stretch_width':
self._toggle[space] = Toggle(label = label, active = False,
height = height, sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text,
height = height, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
elif sizing_mode == 'scale_height' or sizing_mode == 'stretch_height':
self._toggle[space] = Toggle(label = label, active = False,
width = width, sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text,
width = width, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
else:
self._toggle[space] = Toggle(label = label, active = False,
sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
self._toggle[space].js_link('active', self.plot[space], 'visible')
def get_max_prob(self, space):
0
Source : dashboard_app.py
with MIT License
from OpenSourceEconomics
with MIT License
from OpenSourceEconomics
def _create_restart_button(
doc,
database,
session_data,
start_params,
updating_options,
):
"""Create the button that restarts the convergence plots.
Args:
doc (bokeh.Document)
database (sqlalchemy.MetaData): Bound metadata object.
session_data (dict): dictionary with the last retrieved row id
start_params (pd.DataFrame): See :ref:`params`
updating_options (dict): Specification how to update the plotting data.
It contains rollover, update_frequency, update_chunk, jump and stride.
Returns:
bokeh.layouts.Row
"""
# (Re)start convergence plot button
restart_button = Toggle(
active=False,
label="Start Updating",
button_type="danger",
width=200,
height=30,
name="restart_button",
)
restart_callback = partial(
reset_and_start_convergence,
session_data=session_data,
doc=doc,
database=database,
button=restart_button,
start_params=start_params,
updating_options=updating_options,
)
restart_button.on_change("active", restart_callback)
return restart_button
0
Source : outputs.py
with MIT License
from PSLmodels
with MIT License
from PSLmodels
def aggregate_plot(tb):
"""
Function for creating a bokeh plot that shows aggregate tax liabilities for
each year the TaxBrain instance was run
Parameters
----------
tb: An instance of the TaxBrain object
Returns
-------
Bokeh figure
"""
# Pull aggregate data by year and transpose it for plotting
varlist = ["iitax", "payrolltax", "combined"]
base_data = tb.multi_var_table(varlist, "base").transpose()
base_data["calc"] = "Base"
reform_data = tb.multi_var_table(varlist, "reform").transpose()
reform_data["calc"] = "Reform"
base_cds = ColumnDataSource(base_data)
reform_cds = ColumnDataSource(reform_data)
num_ticks = len(base_data)
del base_data, reform_data
fig = figure(title="Aggregate Tax Liability by Year",
width=700, height=500, tools="save")
ii_base = fig.line(x="index", y="iitax", line_width=4,
line_color="#12719e", legend_label="Income Tax - Base",
source=base_cds)
ii_reform = fig.line(x="index", y="iitax", line_width=4,
line_color="#73bfe2", legend_label="Income Tax - Reform",
source=reform_cds)
proll_base = fig.line(x="index", y="payrolltax", line_width=4,
line_color="#408941", legend_label="Payroll Tax - Base",
source=base_cds)
proll_reform = fig.line(x="index", y="payrolltax", line_width=4,
line_color="#98cf90", legend_label="Payroll Tax - Reform",
source=reform_cds)
comb_base = fig.line(x="index", y="combined", line_width=4,
line_color="#a4201d", legend_label="Combined - Base",
source=base_cds)
comb_reform = fig.line(x="index", y="combined", line_width=4,
line_color="#e9807d", legend_label="Combined - Reform",
source=reform_cds)
# format figure
fig.legend.location = "top_left"
fig.yaxis.formatter = NumeralTickFormatter(format="$0.00a")
fig.yaxis.axis_label = "Aggregate Tax Liability"
fig.xaxis.minor_tick_line_color = None
fig.xaxis[0].ticker.desired_num_ticks = num_ticks
# Add hover tool
tool_str = """
< p> < b>@calc - {} < /b> < /p>
< p>${} < /p>
"""
ii_hover = HoverTool(
tooltips=tool_str.format("Individual Income Tax", "@iitax{0,0}"),
renderers=[ii_base, ii_reform]
)
proll_hover = HoverTool(
tooltips=tool_str.format("Payroll Tax", "@payrolltax{0,0}"),
renderers=[proll_base, proll_reform]
)
combined_hover = HoverTool(
tooltips=tool_str.format("Combined Tax", "@combined{0,0}"),
renderers=[comb_base, comb_reform]
)
fig.add_tools(ii_hover, proll_hover, combined_hover)
# toggle which lines are shown
plot_js = """
object1.visible = toggle.active
object2.visible = toggle.active
object3.visible = toggle.active
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base", button_type="primary",
active=True)
base_callback.args = {"toggle": base_toggle, "object1": ii_base,
"object2": proll_base, "object3": comb_base}
base_toggle.js_on_change('active', base_callback)
reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform", button_type="primary",
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": ii_reform,
"object2": proll_reform, "object3": comb_reform}
fig_layout = layout([fig], [base_toggle, reform_toggle])
reform_toggle.js_on_change('active', reform_callback)
# Components needed to embed the figure
data = json_item(fig_layout)
outputs = {
"media_type": "bokeh",
"title": "",
"data": data,
}
return outputs
def create_layout(data, start_year, end_year):
0
Source : outputs.py
with MIT License
from PSLmodels
with MIT License
from PSLmodels
def liability_plot(df_base, df_reform, span, mtr_opt):
df_base = ColumnDataSource(df_base)
df_reform = ColumnDataSource(df_reform)
tools = "pan, zoom_in, zoom_out, reset"
fig = figure(plot_width=600, plot_height=500,
x_range=(-10000, 300000), y_range=(-20000, 100000), tools=tools, active_drag="pan")
fig.yaxis.axis_label = "Tax Liabilities"
fig.yaxis.formatter = NumeralTickFormatter(format="$0,000")
filer_income = Span(location=span, dimension='height',
line_color='black', line_dash='dotted', line_width=1.5)
fig.add_layout(filer_income)
label_format = f'{span:,}'
filer_income_label = Label(x=span, y=25, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size="10pt")
fig.add_layout(filer_income_label)
axis = Span(location=0, dimension='width',
line_color='#bfbfbf', line_width=1.5)
fig.add_layout(axis)
iitax_base = fig.line(x="Axis", y="Individual Income Tax", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, legend_label="Individual Income Tax Liability", muted_alpha=0.1, source=df_base)
payroll_base = fig.line(x="Axis", y="Payroll Tax", line_color='#abdda4', muted_color='#abdda4',
line_width=2, legend_label='Payroll Tax Liability', muted_alpha=0.1, source=df_base)
iitax_reform = fig.line(x="Axis", y="Individual Income Tax", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, line_dash='dashed', legend_label="Individual Income Tax Liability", muted_alpha=0.1, source=df_reform)
payroll_reform = fig.line(x="Axis", y="Payroll Tax", line_color='#abdda4', muted_color='#abdda4',
line_width=2, line_dash='dashed', legend_label='Payroll Tax Liability', muted_alpha=0.1, source=df_reform)
iitax_base.muted = False
payroll_base.muted = False
iitax_reform.muted = False
payroll_reform.muted = False
plot_js = """
object1.visible = toggle.active
object2.visible = toggle.active
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base (Solid)", button_type="default",
active=True)
base_callback.args = {"toggle": base_toggle, "object1": iitax_base,
"object2": payroll_base}
base_toggle.js_on_change('active', base_callback)
reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform (Dashed)", button_type="default",
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": iitax_reform,
"object2": payroll_reform}
reform_toggle.js_on_change('active', reform_callback)
fig.xaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.xaxis.axis_label = mtr_opt
fig.xaxis.minor_tick_line_color = None
fig.legend.click_policy = "mute"
layout = column(fig, row(base_toggle, reform_toggle))
data = json_item(layout)
outputs = {
"media_type": "bokeh",
"title": "Tax Liabilities by {} (Holding Other Inputs Constant)".format(mtr_opt),
"data": data
}
return outputs
def rate_plot(df_base, df_reform, span, mtr_opt):
0
Source : outputs.py
with MIT License
from PSLmodels
with MIT License
from PSLmodels
def rate_plot(df_base, df_reform, span, mtr_opt):
df_base = ColumnDataSource(df_base)
df_reform = ColumnDataSource(df_reform)
tools = "pan, zoom_in, zoom_out, reset"
fig = figure(plot_width=600, plot_height=500,
x_range=(-10000, 300000), y_range=(-0.3, 0.5), tools=tools, active_drag="pan")
fig.yaxis.axis_label = "Tax Rate"
fig.yaxis.formatter = NumeralTickFormatter(format="0%")
filer_income = Span(location=span, dimension='height',
line_color='black', line_dash='dotted', line_width=1.5)
fig.add_layout(filer_income)
label_format = f'{span:,}'
filer_income_label = Label(x=span, y=25, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size="10pt")
fig.add_layout(filer_income_label)
axis = Span(location=0, dimension='width',
line_color='#bfbfbf', line_width=1.5)
fig.add_layout(axis)
iitax_atr_base = fig.line(x="Axis", y="IATR", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, legend_label="Income Tax Average Rate", muted_alpha=0.1, source=df_base)
payroll_atr_base = fig.line(x="Axis", y="PATR", line_color='#abdda4', muted_color='#abdda4',
line_width=2, legend_label='Payroll Tax Average Rate', muted_alpha=0.1, source=df_base)
iitax_mtr_base = fig.line(x="Axis", y="Income Tax MTR", line_color='#fdae61', muted_color='#fdae61',
line_width=2, legend_label="Income Tax Marginal Rate", muted_alpha=0.1, source=df_base)
payroll_mtr_base = fig.line(x="Axis", y="Payroll Tax MTR", line_color='#d7191c', muted_color='#d7191c',
line_width=2, legend_label='Payroll Tax Marginal Rate', muted_alpha=0.1, source=df_base)
iitax_atr_reform = fig.line(x="Axis", y="IATR", line_color='#2b83ba', muted_color='#2b83ba', line_width=2,
line_dash='dashed', legend_label="Income Tax Average Rate", muted_alpha=0.1, source=df_reform)
payroll_atr_reform = fig.line(x="Axis", y="PATR", line_color='#abdda4', muted_color='#abdda4', line_width=2,
line_dash='dashed', legend_label='Payroll Tax Average Rate', muted_alpha=0.1, source=df_reform)
iitax_mtr_reform = fig.line(x="Axis", y="Income Tax MTR", line_color='#fdae61', muted_color='#fdae61',
line_width=2, line_dash='dashed', legend_label="Income Tax Marginal Rate", muted_alpha=0.1, source=df_reform)
payroll_mtr_reform = fig.line(x="Axis", y="Payroll Tax MTR", line_color='#d7191c', muted_color='#d7191c',
line_width=2, line_dash='dashed', legend_label='Payroll Tax Marginal Rate', muted_alpha=0.1, source=df_reform)
iitax_atr_base.muted = False
iitax_mtr_base.muted = True
payroll_atr_base.muted = True
payroll_mtr_base.muted = True
iitax_atr_reform.muted = False
iitax_mtr_reform.muted = True
payroll_atr_reform.muted = True
payroll_mtr_reform.muted = True
plot_js = """
object1.visible = toggle.active
object2.visible = toggle.active
object3.visible = toggle.active
object4.visible = toggle.active
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base (Solid)", button_type="default",
active=True)
base_callback.args = {"toggle": base_toggle, "object1": iitax_atr_base,
"object2": payroll_atr_base, "object3": iitax_mtr_base,
"object4": payroll_mtr_base}
base_toggle.js_on_change('active', base_callback)
reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform (Dashed)", button_type="default",
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": iitax_atr_reform,
"object2": payroll_atr_reform, "object3": iitax_mtr_reform,
"object4": payroll_mtr_reform}
reform_toggle.js_on_change('active', reform_callback)
fig.xaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.xaxis.axis_label = mtr_opt
fig.xaxis.minor_tick_line_color = None
fig.legend.click_policy = "mute"
layout = column(fig, row(base_toggle, reform_toggle))
data = json_item(layout)
outputs = {
"media_type": "bokeh",
"title": "Tax Rates by {} (Holding Other Inputs Constant)".format(mtr_opt),
"data": data
}
return outputs
def credit_plot(df_base, df_reform, span, mtr_opt):
0
Source : outputs.py
with MIT License
from PSLmodels
with MIT License
from PSLmodels
def credit_plot(df_base, df_reform, span, mtr_opt):
df_base = ColumnDataSource(df_base)
df_reform = ColumnDataSource(df_reform)
tools = "pan, zoom_in, zoom_out, reset"
fig = figure(plot_width=600, plot_height=500, x_range=(
-2500, 70000), tools=tools, active_drag="pan")
filer_income = Span(location=span, dimension='height',
line_color='black', line_dash='dotted', line_width=1.5)
fig.add_layout(filer_income)
label_format = f'{span:,}'
filer_income_label = Label(x=span, y=45, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size="10pt")
fig.add_layout(filer_income_label)
axis = Span(location=0, dimension='width',
line_color='#bfbfbf', line_width=1.5)
fig.add_layout(axis)
eitc_base = fig.line(x="Axis", y="EITC", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, legend_label="Earned Income Tax Credit", muted_alpha=0.1, source=df_base)
ctc_base = fig.line(x="Axis", y="CTC", line_color='#abdda4', muted_color='#abdda4',
line_width=2, legend_label='Nonrefundable Child Tax Credit', muted_alpha=0.1, source=df_base)
ctc_refund_base = fig.line(x="Axis", y="CTC Refundable", line_color='#fdae61', muted_color='#fdae61',
line_width=2, legend_label='Refundable Child Tax Credit', muted_alpha=0.1, source=df_base)
cdcc_base = fig.line(x="Axis", y="Child care credit", line_color='#d7191c', muted_color='#d7191c',
line_width=2, legend_label='Child and Dependent Care Credit', muted_alpha=0.1, source=df_base)
eitc_reform = fig.line(x="Axis", y="EITC", line_color='#2b83ba', muted_color='#2b83ba', line_width=2,
line_dash='dashed', legend_label="Earned Income Tax Credit", muted_alpha=0.1, source=df_reform)
ctc_reform = fig.line(x="Axis", y="CTC", line_color='#abdda4', muted_color='#abdda4', line_width=2,
line_dash='dashed', legend_label='Nonrefundable Child Tax Credit', muted_alpha=0.1, source=df_reform)
ctc_refund_reform = fig.line(x="Axis", y="CTC Refundable", line_color='#fdae61', muted_color='#fdae61',
line_width=2, line_dash='dashed', legend_label='Refundable Child Tax Credit', muted_alpha=0.1, source=df_reform)
cdcc_reform = fig.line(x="Axis", y="Child care credit", line_color='#d7191c', muted_color='#d7191c', line_width=2,
line_dash='dashed', legend_label='Child and Dependent Care Credit', muted_alpha=0.1, source=df_reform)
ctc_base.muted = True
ctc_refund_base.muted = True
cdcc_base.muted = True
ctc_reform.muted = True
ctc_refund_reform.muted = True
cdcc_reform.muted = True
plot_js = """
object1.visible = toggle.active
object2.visible = toggle.active
object3.visible = toggle.active
object4.visible = toggle.active
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base (Solid)", button_type="default",
active=True)
base_callback.args = {"toggle": base_toggle, "object1": eitc_base,
"object2": cdcc_base, "object3": ctc_base,
"object4": ctc_refund_base}
base_toggle.js_on_change('active', base_callback)
reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform (Dashed)", button_type="default",
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": eitc_reform,
"object2": cdcc_reform, "object3": ctc_reform,
"object4": ctc_refund_reform}
reform_toggle.js_on_change('active', reform_callback)
fig.yaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.yaxis.axis_label = "Tax Credits"
fig.xaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.xaxis.axis_label = mtr_opt
fig.xaxis.minor_tick_line_color = None
fig.legend.click_policy = "mute"
layout = column(fig, row(base_toggle, reform_toggle))
data = json_item(layout)
outputs = {
"media_type": "bokeh",
"title": "Tax Credits by {} (Holding Other Inputs Constant)".format(mtr_opt),
"data": data
}
return outputs