Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_plot_dict_returned_when_wrap_plot_info_is_false(self, mock_make_id):
doc = Document()
plot1 = figure()
plot1.circle([], [])
doc.add_root(plot1)
plot2 = figure()
plot2.circle([], [])
doc.add_root(plot2)
expected_plotdict_1 = RenderRoot(elementid="ID", id="ID")
expected_plotdict_2 = RenderRoot(elementid="ID", id="ID")
_, plotdict = bes.components(plot1, wrap_plot_info=False)
assert plotdict == expected_plotdict_1
_, plotids = bes.components((plot1, plot2), wrap_plot_info=False)
assert plotids == (expected_plotdict_1, expected_plotdict_2)
ymin.append(min_value)
ymax.append(max_value)
date = datetime(data[varindex['track_date']])
datasource = dict(date=date,
sdate=data[varindex['track_date']],
lat=data[varindex['track_lat']],
lon=data[varindex['track_lon']],
value=data[varindex['data_value']])
sources.append(ColumnDataSource(data=datasource))
zf.close()
shutil.rmtree(csv_dir)
ts_plot = figure(title=plot_title, x_axis_type="datetime", y_axis_type = plot_scale, width=1000, logo=None,
height=400, responsive=True
)
tooltips = [("Date", "@sdate")]
tooltips.append(("Value", "@value{0.000}"))
tooltips.append(("Latitude", "@lat{1.1}"))
tooltips.append(("Longitude", "@lon{1.1}"))
ts_plot.add_tools(CrosshairTool())
ts_plot.xaxis.axis_label = 'Date'
ts_plot.title.text_font_size = "14pt"
ts_plot.xaxis.axis_label_text_font_size = "12pt"
ts_plot.yaxis.axis_label_text_font_size = "12pt"
# Set up the axis label here as it writes to all y axes so overwrites the right hand one
# if we run it later.
xr = Range1d(start=-10, end=10)
yr = Range1d(start=-10, end=10)
# EXERCISE: Plot all the sets of points on different plots p1, p2, p3. Use the
# ranges above for `x_range` and `y_range` for each figure. Set different colors
# as well. Try setting line_color and fill_color instead of just color. You can
# also set alpha, line_alpha, and fill_alpha if you like. Set tools to TOOLS on
# the figures. Change the value of the 'marker' parameter, "circle", "square",
# "triangle", etc. One example is given
p1 = figure(x_range=xr, y_range=yr, tools=TOOLS, plot_width=300, plot_height=300)
p1.scatter(x1, y1, size=12, color="red", alpha=0.5)
p2 = figure(x_range=xr, y_range=yr, tools=TOOLS, plot_width=300, plot_height=300)
p2.scatter(x2, y2, size=12, color="blue", fill_alpha=0.5, marker="square")
p3 = figure(x_range=xr, y_range=yr, tools=TOOLS, plot_width=300, plot_height=300)
p3.scatter(x3, y3, size=12, fill_color="green", line_color="orange", marker="triangle")
# EXERCISE: Try panning and zooming one of the plots with another one visible!
# Set the plot_width and plot_height to smaller if necessary
# EXERCISE: create a new figure p4
p4 = figure(title="Colorful Scatter")
# Lets plot 4000 circles, you can play around with this if you like
N = 4000
# Create a bunch of random points, radii and colors for plotting
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
def create_hgt_figure(sh_df, sz_df):
if sh_df is None or sz_df is None: return figure()
data = {
'date': sh_df.date.tolist(),
'index': sh_df.index.tolist(),
'cum_buy': ((sh_df['cum_buy'] + sz_df['cum_buy'])).round(2).tolist(),
'net_buy': (10 * (sh_df['net_buy'] + sz_df['net_buy'])).round(2).tolist()
}
source = ColumnDataSource(data)
yval_max = max(data['cum_buy'])
p = figure(tools="", toolbar_location=None, x_range=(0, len(data['date'])), y_range=(-yval_max * 0.2, yval_max * 1.3))
mapper = linear_cmap(field_name='net_buy', palette=['red', 'green'], low=0, high=0, low_color = 'green', high_color = 'red')
p.line(x = 'index', y = 'cum_buy', line_width=2, color=Spectral11[0], alpha=0.8, legend_label="沪港通买入累计余额", source = source)
p.vbar(x = 'index', bottom=0, top='net_buy', color=mapper, width=1, legend_label='融资变化', source = source)
p.add_tools(HoverTool(tooltips=[("value", "@cum_buy"), ("date", "@date")]))
p.legend.location = "top_left"
p.legend.click_policy = "hide"
p.legend.orientation = "horizontal"
p.yaxis.axis_label = "沪港通数据概况"
p.xaxis.major_label_overrides = {i: mdate for i, mdate in enumerate(data['date'])}
return p
measured = np.random.lognormal(mu, sigma, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
# compute ideal values
x = np.linspace(0, 8.0, 1000)
pdf = 1/(x* sigma * np.sqrt(2*np.pi)) * np.exp(-(np.log(x)-mu)**2 / (2*sigma**2))
cdf = (1+scipy.special.erf((np.log(x)-mu)/(np.sqrt(2)*sigma)))/2
# EXERCISE: recreate the first plot for this new data
# EXERCISE: (optional): Add new plots for the following distributions:
# * Gamma
# * Beta
# * Weibull
# The numerical code is included, you will need to add renderers to the figures
p3 = figure(title="Gamma Distribution (k=1, θ=2)",
background_fill="#E8DDCB", tools="")
k, theta = 1.0, 2.0
# sample the distribution
measured = np.random.gamma(k, theta, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
# compute ideal values
x = np.linspace(0, 20.0, 1000)
pdf = x**(k-1) * np.exp(-x/theta) / (theta**k * scipy.special.gamma(k))
cdf = scipy.special.gammainc(k, x/theta) / scipy.special.gamma(k)
p4 = figure(title="Beta Distribution (α=2, β=2)",
('Value', '@y{0.2f}')],
formatters={'x': 'datetime'}))
# Set the legend
legend_plot = Legend(items=[("Data ", [self.plot_data]),
("Series Average ", [self.plot_avg]),
("Rolling Average ", [self.plot_trend]),
("Percentile Region ", [self.plot_patch])],
orientation='horizontal')
# Add the layout outside the plot, clicking legend item hides the line
self.figure.add_layout(legend_plot, 'above')
self.figure.legend.click_policy = "hide"
tools = "pan,wheel_zoom,box_zoom,reset,crosshair,save"
self.histograms = figure(plot_width=plot_width, plot_height=275, tools=tools, active_drag="box_zoom")
self.histograms.xaxis.axis_label_text_font_size = options.PLOT_AXIS_LABEL_FONT_SIZE
self.histograms.yaxis.axis_label_text_font_size = options.PLOT_AXIS_LABEL_FONT_SIZE
self.histograms.xaxis.major_label_text_font_size = options.PLOT_AXIS_MAJOR_LABEL_FONT_SIZE
self.histograms.yaxis.major_label_text_font_size = options.PLOT_AXIS_MAJOR_LABEL_FONT_SIZE
self.histograms.min_border_left = options.MIN_BORDER
self.histograms.min_border_bottom = options.MIN_BORDER
self.vbar = self.histograms.vbar(x='x', width='width', bottom=0, top='top', source=self.source['hist'],
color=options.PLOT_COLOR, alpha=options.HISTOGRAM_ALPHA)
self.histograms.xaxis.axis_label = ""
self.histograms.yaxis.axis_label = "Frequency"
self.histograms.add_tools(HoverTool(show_arrow=True, line_policy='next',
tooltips=[('x', '@x{0.2f}'),
('Counts', '@top')]))
self.bokeh_layout = column(self.figure, Div(text='<hr>', width=plot_width), self.histograms)
palette = [cc.rainbow[i] for i in range(len(step_data['mouse'].unique()))]
palette = [cc.rainbow[i*15] for i in range(5)]
mice = sorted(step_data['mouse'].unique())
current_step = step_data.groupby('mouse').last().reset_index()
current_step = current_step[['mouse','step']]
plots = []
p = figure(x_range=step_data['mouse'].unique(),title='Mouse Steps',
plot_height=200)
p.xaxis.major_label_orientation = np.pi / 2
p.vbar(x=current_step['mouse'], top=current_step['step'], width=0.9)
plots.append(p)
for i, (mus, group) in enumerate(step_data.groupby('mouse')):
meancx = group['correct'].ewm(span=100,ignore_na=True).mean()
p = figure(plot_height=100,y_range=(0,1),title=mus)
p.line(group['trial_num'], meancx, color=palette[group['step'].iloc[0]-1])
plots.append(p)
grid = gridplot(plots, ncols=1)
show(grid)
# Get Name of x-axis data:
if kind == "barh":
xlabelname = (
figure_options["y_axis_label"]
if figure_options.get("y_axis_label", "") != ""
else "x"
)
else:
xlabelname = (
figure_options["x_axis_label"]
if figure_options.get("x_axis_label", "") != ""
else "x"
)
# Create Figure for plotting:
p = _figure(**figure_options)
if "x_axis_type" not in figure_options:
figure_options["x_axis_type"] = None
# For categorical plots, set the xticks:
if x_labels_dict is not None:
p.xaxis.formatter = FuncTickFormatter(
code="""
var labels = %s;
return labels[tick];
"""
% x_labels_dict
)
# Use figure when passed by user:
if figure is not None:
p = figure
def make_plot(x, y):
p = figure(title = "Iris Morphology", sizing_mode="fixed", plot_width=400, plot_height=400)
p.xaxis.axis_label = x
p.yaxis.axis_label = y
p.circle(flowers[x], flowers[y], color=colors, fill_alpha=0.2, size=10)
return p
Parameters
----------
conn : DBobject
Connection object that represents database
start : time
Startlimit for x-axis and query (typ. datetime.now()- 4Months)
end : time
Endlimit for x-axis and query (typ. datetime.now())
Return
------
p : Plot object
Bokeh plot
'''
# create a new plot with a title and axis labels
p = figure(tools="pan,wheel_zoom,box_zoom,reset,save", \
toolbar_location="above", \
plot_width=1120, \
plot_height=800, \
y_range=[-6, 4], \
x_range=utils.time_delta(Time(end)), \
x_axis_type='datetime', \
x_axis_label='Date', y_axis_label='ratio (normalized)')
p.xaxis.formatter = copy.copy(utils.plot_x_axis_format)
p.grid.visible = True
p.title.text = "Filterwheel Ratio"
pf.add_basic_layout(p)
pf.add_to_wplot(p, "FND", "IMIR_HK_FW_POS_RATIO_FND", start, end, conn, mn.fw_nominals['FND'], color="green")
pf.add_to_wplot(p, "OPAQUE", "IMIR_HK_FW_POS_RATIO_OPAQUE", start, end, conn, mn.fw_nominals['OPAQUE'], color="red")