Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fig1 = generate_empty_figure()
# nothing happens when no trades are available
fig = plot_trades(fig1, None)
assert fig == fig1
assert log_has("No trades found.", caplog)
pair = "ADA/BTC"
filename = testdatadir / "backtest-result_test.json"
trades = load_backtest_data(filename)
trades = trades.loc[trades['pair'] == pair]
fig = plot_trades(fig, trades)
figure = fig1.layout.figure
# Check buys - color, should be in first graph, ...
trade_buy = find_trace_in_fig_data(figure.data, "trade_buy")
assert isinstance(trade_buy, go.Scatter)
assert trade_buy.yaxis == 'y'
assert len(trades) == len(trade_buy.x)
assert trade_buy.marker.color == 'green'
trade_sell = find_trace_in_fig_data(figure.data, "trade_sell")
assert isinstance(trade_sell, go.Scatter)
assert trade_sell.yaxis == 'y'
assert len(trades) == len(trade_sell.x)
assert trade_sell.marker.color == 'red'
def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
"""
Add trades to "fig"
"""
# Trades can be empty
if trades is not None and len(trades) > 0:
trade_buys = go.Scatter(
x=trades["open_time"],
y=trades["open_rate"],
mode='markers',
name='trade_buy',
marker=dict(
symbol='square-open',
size=11,
line=dict(width=2),
color='green'
)
)
# Create description for sell summarizing the trade
desc = trades.apply(lambda row: f"{round(row['profitperc'], 3)}%, {row['sell_reason']}, "
f"{row['duration']} min",
axis=1)
trade_sells = go.Scatter(
x, y, labels = [], [], []
for i in range(len(self.pxrd)):
theta2, d, h, k, l, I = self.pxrd[i]
h, k, l = int(h), int(k), int(l)
if I > minimum_I:
label = '<br>2θ: {:6.2f}<br>d: {:6.4f}<br>I: {:6.4f}<br>hkl: ({:d}{:d}{:d})'.format(theta2, d, I, h, k, l)
x.append(theta2)
y.append(-0.1)
labels.append(label)
trace1 = go.Bar(x=x, y=y, text=labels,
hovertemplate = "%{text}",
width=0.2, name='Index')
trace2 = go.Scatter(x=self.spectra[0], y=self.spectra[1], name='Profile')
fig = go.Figure(data=[trace2, trace1])
fig.update_layout(xaxis_title = '2θ ({:.4f} Å)'.format(self.wavelength),
yaxis_title = 'Intensity',
title = 'PXRD of '+self.name)
if os.environ['_'].find('jupyter') == -1:
if html is None:
return fig.to_html()
else:
fig.write_html(html)
else:
print("This is running on Jupyter Notebook")
return fig
if n_qubits > 50:
qubit_size = 20
font_size = 9
qtext_color = []
for ii in range(n_qubits):
if background_color == 'black':
if single_gate_errors[ii] > 0.8*max_1q_err:
qtext_color.append('black')
else:
qtext_color.append('white')
else:
qtext_color.append('white')
fig.append_trace(go.Scatter(
x=[d[1] for d in grid_data],
y=[-d[0]-offset for d in grid_data],
mode="markers+text",
marker=go.scatter.Marker(size=qubit_size,
color=q_colors,
opacity=1),
text=[str(ii) for ii in range(n_qubits)],
textposition="middle center",
textfont=dict(size=font_size, color=qtext_color),
hoverinfo="text",
hovertext=qubit_text), row=1, col=3)
fig.update_xaxes(row=1, col=3, visible=False)
_range = None
if offset:
_range = [-3.5, 0.5]
sizes = [smallest_size] * (len(evaluations) - d_size_min_max) + sizes
if selected_pipeline is not None:
sizes = [
size if id_ != selected_pipeline else selected_size
for size, id_ in zip(sizes, evaluations.id)
]
default_color = "#301cc9"
selected_color = "#c81818"
colors = [
default_color if id_ != selected_pipeline else selected_color
for id_ in evaluations.id
]
all_scatter = go.Scatter(
x=evaluations[metric_one],
y=-evaluations[metric_two],
mode="markers",
marker={"color": colors, "size": sizes},
name="all evaluations",
text=[self.report.individuals[id_].short_name() for id_ in evaluations.id],
customdata=evaluations.id,
)
return [all_scatter]
def make_figure(report, xaxis, yaxis, mode='lines'):
return {
'data': [
go.Scatter(
name=f'GAMA',
x=report.evaluations[xaxis],
y=report.evaluations[yaxis],
text=report.evaluations.pipeline,
mode=mode
)
],
'layout': {
'title': f'log name',
'xaxis': {'title': f'n'},
'yaxis': {'title': f'{yaxis}'}
}
scores_over_time = pd.DataFrame(end_time_series)
for log_no in method_agg.log_no.unique():
log_results = method_agg[method_agg.log_no == log_no]
best_for_log = pd.merge_asof(
end_time_series,
log_results[["relative_end", y_axis]],
on="relative_end",
)
scores_over_time[f"log{log_no}"] = best_for_log[y_axis]
scores_over_time = scores_over_time.set_index("relative_end")
mean_scores = scores_over_time.mean(axis=1)
std_scores = scores_over_time.std(axis=1)
scores_over_time["mean"] = mean_scores
scores_over_time["std"] = std_scores
upper_bound = go.Scatter(
x=scores_over_time.index,
y=scores_over_time["mean"] + scores_over_time["std"],
mode="lines",
marker=dict(color=soft_colors[color_no]),
line=dict(width=0),
fillcolor=soft_colors[color_no],
fill="tonexty",
showlegend=False,
)
mean_performance = go.Scatter(
name=method,
x=scores_over_time.index,
y=scores_over_time["mean"],
mode="lines",
line=dict(color=hard_colors[color_no]),
def linearchart(x_values, y_values, log_scale, chart_title, lbl_x, lbl_y):
scatter = go.Scatter(
x=x_values,
y=y_values,
mode='lines+markers'
)
fig = go.Figure(data=scatter)
font_title = dict(
family="Courier New, monospace",
size=18,
color="#9f9f9f"
)
font_axes = dict(
family="Courier New, monospace",
size=13,
def plot_precision_recall_vs_threshold_plotly(self, legend = True, threshold = False, methods=None, number_threshold = 100):
fig = go.Figure()
for i, (Y_test, prediction) in enumerate(self.data):
metrics = Metrics(Y_test, prediction)
precisions, recalls = metrics.PRC_Value(number_threshold)
fig.add_trace(go.Scatter(x=np.linspace(1.0, 0.0, num=len(precisions)-1), y=precisions[:-1],
mode='lines',
name='Precision'))
fig.add_trace(go.Scatter(x=np.linspace(1.0, 0.0, num=len(precisions)-1), y=recalls[:-1],
mode='lines',
name='Recall'))
if threshold:
opt = Optimum(Y_test, prediction)
if "Distance PRC" in methods:
threshold_PRC, object_PRC = opt.optimum_for_PRC()
fig.add_trace(go.Scatter(x=[threshold_PRC], y=[object_PRC.precision()],
name="Distance_PRC threshold precision {} ".format(threshold_PRC),
mode = "markers",
line=dict(color='royalblue', width=4, dash='dot')))
fig.add_trace(go.Scatter(x=[threshold_PRC], y=[object_PRC.sensitivity()],
showlegend=False,
line=dict(color='royalblue', width=4, dash='dot')))