#!/usr/bin/env python
# coding: utf-8
import plotly.graph_objects as go
def tri_estimation_graph(bx, tri_estimation_name='TRI_current_estimations', filename=''):
if not filename:
filename = 'store/%s_%s_%s_graph'%(bx.gm_signature, repr(bx), tri_estimation_name)
data = bx.guessbox.estimations[tri_estimation_name]
x=data[0]
# it can be effectively done with pandas
p_f = []
p_mix = []
p_outside = []
p_success = []
for estimation in data[1]:
# -1 = 'out', 0=success, 1=failure, 2=mix
p_f.append(estimation[1])
p_mix.append(estimation[2])
p_outside.append(estimation[-1])
p_success.append(estimation[0])
# uplně hahoru - success
# outside
# mix
# uplně dolu - failure
fig = go.Figure()
fig.add_trace(go.Scatter(
x=x, y=p_f,
mode='lines',
line=dict(width=0.5, color='red'), #rgb(184, 247, 212)
name="Failure",
stackgroup='one',
groupnorm='fraction' # sets the normalization for the sum of the stackgroup
))
fig.add_trace(go.Scatter(
x=x, y=p_mix,
mode='lines',
line=dict(width=0.5, color='orange'),
name="Mixed",
stackgroup='one'
))
fig.add_trace(go.Scatter(
x=x, y=p_outside,
mode='lines',
line=dict(width=0.5, color='white'),
name="Outside",
stackgroup='one'
))
fig.add_trace(go.Scatter(
x=x, y=p_success,
mode='lines',
line=dict(width=0.5, color='green'),
name="Success",
stackgroup='one'
))
try:
fig.add_trace(go.Scatter(x=(min(x),max(x)), y=(bx.pf_exact,bx.pf_exact),
mode='lines',
name=bx.pf_exact_method,
line=dict(color='blue')))
except AttributeError:
pass
fig.update_layout(
showlegend=True,
#xaxis_type='category',
yaxis=dict(
type='linear',
range=[0, 1],
#ticksuffix='%'
))
# zatím nechcu nikomu nic zobrazovat
#fig.show()
fig.write_html(filename + ".html")
# kdyby někdo chtěl statické obrázky
# musí mať psutil nainštalovany
try:
fig.write_image(filename + ".png")
except:
pass
# vratíme figuru,
# uživatel by mohl s ní eště něčo udělat
return fig
# 3D plot requires WebGL support
# which is not currently availiable under Haiku.
#
#import plotly.graph_objects as go
#import numpy as np
#
## Helix equation
#t = np.linspace(0, 10, 50)
#x, y, z = np.cos(t), np.sin(t), t
#
#fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z,
# mode='markers')])
#fig.show()
#