Skip to main content

Plotly graph for labelling timeserie data

Project description

streamlit-label-graph

Plotly graph for labelling timeserie data

pip install streamlit-label-graph
import streamlit as st

import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots

from streamlit_label_graph import label_graph, LabelConfig


@st.cache_data
def weather_data ():
    x = pd.date_range(start='2022-01-01', end='2022-12-31', freq='D')
    y = np.sin(2 * np.pi * x.dayofyear / 365) + np.random.normal(0, 0.1, size=len(x))
    return pd.DataFrame({'date': x, 'temperature': y})

config: LabelConfig = {
    'categories': [
        {'key': 'HOT', 'color': 'rgba(255 110 110,0.1)'},
        {'key': 'COLD', 'color': 'rgba(110,110,255,0.1)'}
    ]
}
df = weather_data()

figure = px.line(df, x=df['date'], y=df['temperature'])
labels = label_graph(figure, config)
df['label'] = labels['series']

fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(go.Line(x=df['date'], y=df['temperature'], name='temperature'), secondary_y=False)
fig.add_trace(go.Line(x=df['date'], y=df['label'], name='label'), secondary_y=True)
st.write(fig)
st.write(labels)
  • Use Ctrl + Mouse-drag to create a new label
  • Right click on a label to set the category

Demo

Run demo

python -m streamlit_label_graph

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit-label-graph-0.1.2.tar.gz (63.9 kB view hashes)

Uploaded Source

Built Distribution

streamlit_label_graph-0.1.2-py3-none-any.whl (64.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page