Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _parse_module(module):
"""Sort the members of a module into dictionaries of functions
(sequences) and classes (mappings)."""
test = lambda nm, mem: (not nm.startswith("_")) and (module.__name__ in mem.__module__)
seqs = {nm: mem for nm, mem in getmembers(module, isfunction) if test(nm, mem)}
maps = {nm: mem for nm, mem in getmembers(module, isclass) if test(nm, mem)}
# these need to be mappings
if 'gridplot' in seqs:
maps['gridplot'] = seqs.pop('gridplot')
if 'Donut' in seqs:
maps['Donut'] = seqs.pop('Donut')
return (seqs, maps)
for module in [models, plotting, layouts, palettes, transform]:
seqs, maps = _parse_module(module)
bokeh_sequences.update(seqs)
bokeh_mappings.update(maps)
source = bp.ColumnDataSource(
data=dict(event=evt_list,
begin=begin_list,
start=start_list,
stop=stop_list,
duration=dur_list,
duration_formated=[format_time(t) for t in dur_list],
percent=["{0:.1%}".format(d/stop_list[-1])
for d in dur_list],
color=color_list)
)
# Plot
minheight = 150
bp.output_file(self._output)
total_seconds = stop_list[-1]
tools = "resize,hover,save,pan,box_zoom,reset"
fig_timeline = bp.figure(title='',
width=1200,
height=max(minheight, 50 * len(evt_color)),
y_range=list(reversed(evt_range)),
x_range=(0, total_seconds + 1),
x_axis_location="above",
tools=tools)
fig_timeline.rect(x="begin", y="event", width="duration", height=1,
fill_color="color", source=source, fill_alpha=0.8,
line_color="color")
fig_timeline.ygrid[0].grid_line_color=None
# first query data necessary for all series in every figure
for subplot in layout_input['subplots']:
for series in subplot['series']:
series['self'].query()
# next create plots
for subplot in layout_input['subplots']:
figure_kwargs = subplot.get('figure_kwargs', casm.plotting.default_figure_kwargs)
r = subplot['pos'][0]
c = subplot['pos'][1]
## Construct a figure
fig = bokeh.plotting.Figure(**figure_kwargs)
tap_action = casm.plotting.TapAction(data)
renderers = []
for series in subplot['series']:
series['self'].plot(fig, tap_action=tap_action)
renderers += series['self'].renderers
# add tools
fig.add_tools(tap_action.tool())
fig.add_tools(bokeh.models.BoxSelectTool(renderers=renderers))
fig.add_tools(bokeh.models.LassoSelectTool(renderers=renderers))
layout[r][c] = fig
gplot = bokeh.layouts.layout(layout, plot_width=400, plot_height=400)
doc.add_root(gplot)
try:
file_ = open(self.output, 'r')
file_.close()
raise ValueError(_('ERROR: File {} exists.\nUse `-f` to overwrite').format(self.output))
except FileNotFoundError:
pass
if not self.already_scaled:
self.scale()
try:
self.ppsbt
except AttributeError:
self.set_percent_problems_solved_by_time()
plt.output_file(self.output, title=self.plot_lang(self.title))
# Axis
try:
maxt = min(max(self.times), self.tau)
except (AttributeError, TypeError):
maxt = max(self.times)
boken_plot_options = {"x_range":[1,maxt], "y_range":[0,1]}
# Change the xscale to log scale
if self.semilog:
boken_plot_options["x_axis_type"] = "log"
p = plt.figure(title=self.plot_lang(self.title),
x_axis_label=self.plot_lang(self.ylabel),
y_axis_label=self.plot_lang(self.xlabel),
def _plot_bokeh_grid(self):
if len(self.plots) > 0:
grid = GridPlot(children=partition(self.plots, self.nrows), title=self.title)
plotting.show(grid)
):
"""Bokeh loo pit plot."""
if backend_kwargs is None:
backend_kwargs = {}
backend_kwargs = {
**backend_kwarg_defaults(
("tools", "plot.bokeh.tools"),
("output_backend", "plot.bokeh.output_backend"),
("dpi", "plot.bokeh.figure.dpi"),
),
**backend_kwargs,
}
dpi = backend_kwargs.pop("dpi")
if ax is None:
ax = bkp.figure(width=int(figsize[0] * dpi), height=int(figsize[1] * dpi), **backend_kwargs)
if ecdf:
if plot_kwargs.get("drawstyle") == "steps-mid":
ax.step(
np.hstack((0, loo_pit, 1)),
np.hstack((0, loo_pit - loo_pit_ecdf, 0)),
line_color=plot_kwargs.get("color", "black"),
line_alpha=plot_kwargs.get("alpha", 1.0),
line_width=plot_kwargs.get("linewidth", 3.0),
mode="center",
)
else:
ax.line(
np.hstack((0, loo_pit, 1)),
np.hstack((0, loo_pit - loo_pit_ecdf, 0)),
line_color=plot_kwargs.get("color", "black"),
_BOKEH_OUTPUT_NOTEBOOK_ACTIVATED = True
current_plot = bkh.figure(title=title, plot_width=figsize[0], plot_height=figsize[1])
_COLOR_CYCLE_BOKEH = itertools.cycle(COLOR_ARRAY_BOKEH)
if xlim is not None:
current_plot.x_range = Range1d(start=xlim[0], end=xlim[1])
if ylim is not None:
current_plot.y_range = Range1d(start=ylim[0], end=ylim[1])
current_plot.title_text_font_size = value("{}pt".format(fontsize))
current_plot.xaxis.axis_label = xlabel
current_plot.yaxis.axis_label = ylabel
current_plot.legend.orientation = 'top_right'
current_plot = self._plot_bokeh(current_plot, show_legend)
bkh.show(current_plot)
```python
import streamlit as st
import bokeh.plotting
circle_chart = bokeh.plotting.figure(sizing_mode="stretch_width", height=200)
circle_chart.circle(
[1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5
)
st.bokeh_chart(circle_chart)
```
"""
)
# st.echo causing error when run via eval. So I've included the code above directly
sidebar_settings()
circle_chart = bokeh.plotting.figure(sizing_mode="stretch_width", height=200)
circle_chart.circle(
[1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5
)
st.bokeh_chart(circle_chart)
st.markdown(
"""
As you will see below you can actually take advantage of many of the super powers of Bokeh
like layouts, widgets, jslink and potentially even Python callbacks.
The technical reason being that
[`st.bokeh_chart`](https://streamlit.io/docs/api.html?highlight=bokeh_chart#streamlit.bokeh_chart)
is capable of using
[`bokeh.model.Model`](https://docs.bokeh.org/en/latest/docs/reference/model.html) and not just
[`bokeh.plotting.Figure`](https://docs.bokeh.org/en/latest/docs/reference/plotting.html)
objects.
p.grid.grid_line_alpha = 0
p.xaxis.axis_label = 'Time (seconds)'
p.yaxis.axis_label = 'Voltage'
p.circle(x_downsamp, y_downsamp, size=4, legend='50hz interpolation',
color='darkgrey', alpha=0.2)
window_size = 30
window = np.ones(window_size)/float(window_size)
#data_avg = np.convolve(y_downsamp, window, 'valid')
p.line(x_downsamp, filtered, legend='filtered', color='black')
p.legend.location = "top_left"
bp.show(p)