|
import plotly.graph_objs as go |
|
from plotly.subplots import make_subplots |
|
|
|
from ._scribble import series |
|
|
|
|
|
|
|
def __create_fig(): |
|
fig = make_subplots( |
|
rows=2, |
|
cols=1, |
|
row_heights=[0.5, 0.5], |
|
vertical_spacing=0.1, |
|
subplot_titles=["", ""], |
|
) |
|
return fig |
|
|
|
|
|
def __create_annotation(fig, word): |
|
|
|
fig.add_annotation( |
|
x=0.5, |
|
y=1, |
|
text=word, |
|
showarrow=False, |
|
font=dict(size=20, color="blue"), |
|
textangle=180, |
|
align="center", |
|
valign="middle", |
|
row=1, |
|
col=1, |
|
) |
|
|
|
|
|
def __remove_axis(fig): |
|
|
|
fig.update_layout( |
|
plot_bgcolor="white", |
|
paper_bgcolor="white", |
|
showlegend=False, |
|
margin=dict(l=30, r=30, t=30, b=30), |
|
) |
|
|
|
|
|
fig.update_xaxes( |
|
row=1, |
|
col=1, |
|
showgrid=False, |
|
zeroline=False, |
|
showticklabels=False, |
|
showline=False, |
|
) |
|
fig.update_yaxes( |
|
row=1, |
|
col=1, |
|
showgrid=False, |
|
zeroline=False, |
|
showticklabels=False, |
|
showline=False, |
|
) |
|
|
|
|
|
fig.update_xaxes( |
|
row=2, |
|
col=1, |
|
showgrid=True, |
|
zeroline=False, |
|
showticklabels=False, |
|
showline=False, |
|
) |
|
fig.update_yaxes( |
|
row=2, |
|
col=1, |
|
showgrid=True, |
|
zeroline=False, |
|
showticklabels=False, |
|
showline=False, |
|
) |
|
return fig |
|
|
|
|
|
def __plot_letters(fig, d): |
|
|
|
traces = [] |
|
|
|
for segment in d: |
|
trace = go.Scatter( |
|
x=segment.real, |
|
y=segment.imag, |
|
mode="markers+lines", |
|
showlegend=False, |
|
line={"width": 3, "color": "blue"}, |
|
marker={"size": 3, "color": "blue"}, |
|
) |
|
traces.append(trace) |
|
|
|
|
|
for trace in traces: |
|
fig.add_trace(trace, row=2, col=1) |
|
|
|
|
|
def create(name, fct, event, n=100): |
|
|
|
fig = __create_fig() |
|
__create_annotation(fig, word=f"{name}<br>{fct}<br>{event}") |
|
|
|
segments = list(series(name, n=n, str=fct)) |
|
|
|
|
|
|
|
|
|
__plot_letters(fig, segments) |
|
__remove_axis(fig) |
|
return fig |
|
|