Add animation slider
This commit is contained in:
parent
bb201c83b5
commit
4d0a025001
@ -4,7 +4,7 @@ import plotly.express as px
|
|||||||
|
|
||||||
TABLE_NAME = "stats"
|
TABLE_NAME = "stats"
|
||||||
|
|
||||||
INTERVAL = 20 # on cron interval is 10min
|
INTERVALS = [50, 100, 1000] # on cron interval is 10min
|
||||||
|
|
||||||
|
|
||||||
# Create your connection.
|
# Create your connection.
|
||||||
@ -12,10 +12,19 @@ cnx = sqlite3.connect('data.sqlite')
|
|||||||
|
|
||||||
df = pd.read_sql_query(f"SELECT * FROM {TABLE_NAME}", cnx)
|
df = pd.read_sql_query(f"SELECT * FROM {TABLE_NAME}", cnx)
|
||||||
df = df.set_index("date")
|
df = df.set_index("date")
|
||||||
df = df[::INTERVAL]
|
|
||||||
print(f"Find {len(df)} items")
|
print(f"Find {len(df)} items")
|
||||||
|
|
||||||
|
df["granu"] = 1
|
||||||
|
|
||||||
fig = px.area(df, title="Wide-Form Input")
|
dfs = pd.DataFrame()
|
||||||
|
for i in INTERVALS:
|
||||||
|
dfi = df[::i].copy()
|
||||||
|
dfi["granu"] = i
|
||||||
|
dfs = dfs.append(dfi)
|
||||||
|
|
||||||
|
print(f"Find {len(dfs)} items")
|
||||||
|
fig = px.area(dfs, title="Wide-Form Input", animation_frame="granu")
|
||||||
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
||||||
|
fig["layout"].pop("updatemenus") # optional, drop animation buttons
|
||||||
|
fig.update_layout(transition = {'duration': 1e12})
|
||||||
fig.write_html("stats.html", include_plotlyjs="cdn")
|
fig.write_html("stats.html", include_plotlyjs="cdn")
|
||||||
|
Loading…
Reference in New Issue
Block a user