β¬Β Β Chart annotations
Submitted by Arnaud Miribel
Summary
Add annotations to specific timestamps in your time series in Altair!
Functions
get_annotations_chart
Creates an Altair Chart with annotation markers on the horizontal axis. Useful to highlight certain events on top of another time series Altair Chart. More here https://share.streamlit.io/streamlit/example-app-time-series-annotation/main
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotations |
Iterable[Tuple]
|
Iterable of annotations defined by tuples with date and annotation. |
required |
y |
float
|
Height at which the annotation marker should be. Defaults to 0. |
0
|
min_date |
str
|
Only annotations older than min_date will be displayed. Defaults to None. |
None
|
max_date |
str
|
Only annotations more recent than max_date will be displayed. Defaults to None. |
None
|
marker |
str
|
Marker to be used to indicate there is an annotation. Defaults to "β¬". |
'β¬'
|
marker_size |
float
|
Size of the marker (font size). Defaults to 20. |
20
|
marker_offset_x |
float
|
Horizontal offset. Defaults to 0. |
0
|
market_offset_y |
float
|
Vertical offset. Defaults to -10. |
-10
|
marker_align |
str
|
Text-align property of the marker ("left", "right", "center"). Defaults to "center". |
'center'
|
Returns:
Type | Description |
---|---|
Chart
|
alt.Chart: Altair Chart with annotation markers on the horizontal axis |
Source code in src/streamlit_extras/chart_annotations/__init__.py
Import:
- You should add this to the top of your .py file
Examples
example
def example() -> None:
data: pd.DataFrame = get_data()
chart: alt.TopLevelMixin = get_chart(data=data)
chart += get_annotations_chart(
annotations=[
("Mar 01, 2008", "Pretty good day for GOOG"),
("Dec 01, 2007", "Something's going wrong for GOOG & AAPL"),
("Nov 01, 2008", "Market starts again thanks to..."),
("Dec 01, 2009", "Small crash for GOOG after..."),
],
)
st.altair_chart(chart, use_container_width=True) # type: ignore