Nice / pages /666_๐Ÿ˜_TEST.py
betterme
update
b966bc9
raw
history blame
1.8 kB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project : Python.
# @File : 666_๐Ÿ˜_TEST
# @Time : 2023/3/9 ไธŠๅˆ10:28
# @Author : yuanjie
# @WeChat : meutils
# @Software : PyCharm
# @Description : https://github.com/streamlit/example-app-commenting/blob/main/streamlit_app.py
"""
ไธๆ–ญๅˆทๆ–ฐๆ•ฐๆฎๅ›พ่กจ
https://blog.csdn.net/qq_42761569/article/details/123418493
http://cw.hubwiz.com/card/c/streamlit-manual/1/6/13/
"""
import altair as alt
def get_chart(data):
# ้ผ ๆ ‡ๆ‚ฌๅœ
hover = alt.selection_single(
fields=["date"],
nearest=True,
on="mouseover",
empty="none",
)
lines = (
alt.Chart(data, title="Evolution of stock prices")
.mark_line()
.encode(
x="date",
y="price",
color="symbol",
strokeDash="symbol",
)
)
# Draw points on the line, and highlight based on selection
points = lines.transform_filter(hover).mark_circle(size=65)
# Draw a rule at the location of the selection
tooltips = (
alt.Chart(data)
.mark_rule()
.encode(
x="date",
y="price",
opacity=alt.condition(hover, alt.value(0.3), alt.value(0)),
tooltip=[
alt.Tooltip("date", title="Date"),
alt.Tooltip("price", title="Price (USD)"),
],
)
.add_selection(hover)
)
return (lines + points + tooltips).interactive()
# source = data.stocks()
# all_symbols = source.symbol.unique()
# symbols = st.multiselect("Choose stocks to visualize", all_symbols, all_symbols[:3])
#
#
# source = source[source.symbol.isin(symbols)]
# chart = get_chart(source)
# st.altair_chart(chart, use_container_width=True)