streamlit

Форк
0
/
st_map.py 
92 строки · 2.0 Кб
1
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from typing import Any, cast
16

17
import numpy as np
18
import pandas as pd
19

20
import streamlit as st
21
from tests.streamlit import pyspark_mocks
22
from tests.streamlit.snowpark_mocks import DataFrame as MockedSnowparkDataFrame
23
from tests.streamlit.snowpark_mocks import Table as MockedSnowparkTable
24

25
"""
26
### Empty map
27
"""
28

29
st.map()
30

31

32
"""
33
### st.map with pyspark.sql.DataFrame
34
"""
35

36
st.map(pyspark_mocks.DataFrame(is_map=True))
37

38
"""
39
### st.map with unevaluated Snowpark Table
40
"""
41

42
st.map(MockedSnowparkTable(is_map=True, num_of_rows=50000))
43

44
"""
45
### st.map with unevaluated Snowpark DataFrame
46
"""
47

48
st.map(MockedSnowparkDataFrame(is_map=True, num_of_rows=50000))
49

50
"""
51
### Simple map
52
"""
53

54
# Cast is needed due to mypy not understanding the outcome of dividing
55
# an array by a list of numbers.
56
np.random.seed(0)
57
coords: "np.typing.NDArray[np.float_]" = cast(
58
    Any,
59
    np.random.randn(1000, 2) / [50, 50],
60
) + [37.76, -122.4]
61
df = pd.DataFrame(coords, columns=["lat", "lon"])
62

63
st.map(df)
64

65

66
"""
67
### Simple map with zoom
68
"""
69

70
st.map(df, zoom=8)
71

72

73
"""
74
### Map with color and size layers
75
"""
76

77
df = pd.DataFrame(
78
    {
79
        "xlat": [38.8762997, 38.8742997, 38.9025842],
80
        "xlon": [-77.0037, -77.0057, -77.0556545],
81
        "color": ["#f00", "#f0f", "#00f"],
82
        "size": [1000, 500, 300],
83
    }
84
)
85

86
st.map(
87
    df,
88
    latitude="xlat",
89
    longitude="xlon",
90
    color="color",
91
    size="size",
92
)
93

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.