示例#1
0
def render_dataset():
    with st.echo("below"):
        options = {
            "legend": {},
            "tooltip": {},
            "dataset": {
                "source": [
                    ["product", "2015", "2016", "2017"],
                    ["Matcha Latte", 43.3, 85.8, 93.7],
                    ["Milk Tea", 83.1, 73.4, 55.1],
                    ["Cheese Cocoa", 86.4, 65.2, 82.5],
                    ["Walnut Brownie", 72.4, 53.9, 39.1],
                ]
            },
            "xAxis": {"type": "category"},
            "yAxis": {},
            "series": [{"type": "bar"}, {"type": "bar"}, {"type": "bar"}],
        }
        st_echarts(options, renderer="svg")
示例#2
0
def render_liquid():
    with st.echo("below"):
        options = {
            "series": [
                {
                    "type": "liquidFill",
                    "data": [0.5, 0.4, 0.3],
                    "color": ["red", "#0f0", "rgb(0, 0, 255)"],
                    "itemStyle": {"opacity": 0.6},
                    "emphasis": {"itemStyle": {"opacity": 0.9}},
                }
            ]
        }
        st_echarts(options)

        c = (
            Liquid()
            .add("lq", [0.6, 0.7])
            .set_global_opts(title_opts=opts.TitleOpts(title="Liquid-基本示例"))
        )
        st_pyecharts(c)
示例#3
0
def render_basic_line():
    with st.echo("below"):
        options = {
            "xAxis": {
                "type": "category",
                "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            },
            "yAxis": {"type": "value"},
            "series": [
                {"data": [820, 932, 901, 934, 1290, 1330, 1320], "type": "line"}
            ],
        }
        st_echarts(
            options=options,
            height="400px",
        )
        st_echarts(
            options=options,
            height="400px",
            theme="dark",
        )
示例#4
0
def render_event():
    with st.echo("below"):
        st.markdown("Click on chart elements")
        options = {
            "xAxis": {
                "data": [
                    "shirt", "cardign", "chiffon shirt", "pants", "heels",
                    "socks"
                ]
            },
            "yAxis": {},
            "series": [{
                "name": "sales",
                "type": "bar",
                "data": [5, 20, 36, 10, 10, 20]
            }],
        }
        events = {
            "click": "function(params, echarts) {alert('click detection');}"
        }
        st_echarts(options, events=events)
示例#5
0
def bar_status_completion(planning_summary):
    df = planning_summary[planning_summary["status_completion"] != "On Progress"]
    counting = df["status_completion"].value_counts()
    xaxis = counting.index.tolist()
    yaxis = counting.tolist()
    st_echarts({
        "title": {
            "text": "Planning Completion"
        },
        # "legend": {
        #     "data": ['completion']
        # },
        "xAxis": {
            "type": "category",
            "data": xaxis
        },
        "yAxis": { "type": "value" },
        "series": [
            {"data": yaxis, "type": "bar" }
        ],
    })
示例#6
0
def render_basic_tree():
    with open("./data/flare.json", "r") as f:
        data = json.loads(f.read())

    for idx, _ in enumerate(data["children"]):
        data["children"][idx]["collapsed"] = idx % 2 == 0

    option = {
        "tooltip": {"trigger": "item", "triggerOn": "mousemove"},
        "series": [
            {
                "type": "tree",
                "data": [data],
                "top": "1%",
                "left": "7%",
                "bottom": "1%",
                "right": "20%",
                "symbolSize": 7,
                "label": {
                    "position": "left",
                    "verticalAlign": "middle",
                    "align": "right",
                    "fontSize": 9,
                },
                "leaves": {
                    "label": {
                        "position": "right",
                        "verticalAlign": "middle",
                        "align": "left",
                    }
                },
                "emphasis": {"focus": "descendant"},
                "expandAndCollapse": True,
                "animationDuration": 550,
                "animationDurationUpdate": 750,
            }
        ],
    }
    st_echarts(option, height="500px")
示例#7
0
def render_effect_scatter():
    with st.echo("below"):
        options = {
            "xAxis": {"scale": True},
            "yAxis": {"scale": True},
            "series": [
                {
                    "type": "effectScatter",
                    "symbolSize": 20,
                    "data": [[161.2, 51.6], [167.5, 59]],
                },
                {
                    "type": "scatter",
                    "data": [
                        [161.2, 51.6],
                        [167.5, 59.0],
                        [159.5, 49.2],
                        [157.0, 63.0],
                        [155.8, 53.6],
                        [170.0, 59.0],
                        [159.1, 47.6],
                        [166.0, 69.8],
                        [176.2, 66.8],
                        [160.2, 75.2],
                        [172.5, 55.2],
                        [170.9, 54.2],
                        [172.9, 62.5],
                        [153.4, 42.0],
                        [160.0, 50.0],
                        [176.5, 71.8],
                        [164.4, 55.5],
                        [160.7, 48.6],
                        [174.0, 66.4],
                        [163.8, 67.3],
                    ],
                },
            ],
        }
        st_echarts(options)
示例#8
0
def render_datazoom():
    with st.echo("below"):
        data = [
            ["14.616", "7.241", "0.896"],
            ["3.958", "5.701", "0.955"],
            ["2.768", "8.971", "0.669"],
            ["9.051", "9.710", "0.171"],
            ["14.046", "4.182", "0.536"],
            ["12.295", "1.429", "0.962"],
            ["4.417", "8.167", "0.113"],
            ["0.492", "4.771", "0.785"],
            ["7.632", "2.605", "0.645"],
            ["14.242", "5.042", "0.368"],
        ]
        option_js = {
            "xAxis": {
                "type": "value"
            },
            "yAxis": {
                "type": "value"
            },
            "dataZoom": [{
                "type": "slider",
                "start": 10,
                "end": 60
            }],
            "series": [{
                "type":
                "scatter",
                "itemStyle": {
                    "opacity": 0.8
                },
                "symbolSize":
                JsCode("""function (val) {  return val[2] * 40; }""").js_code,
                "data":
                data,
            }],
        }
        st_echarts(options=option_js)
示例#9
0
def render_calendar_heatmap():
    with st.echo("below"):

        def get_virtual_data(year):
            date_list = pd.date_range(
                start=f"{year}-01-01", end=f"{year + 1}-01-01", freq="D"
            )
            return [[d.strftime("%Y-%m-%d"), randint(1, 10000)] for d in date_list]

        options = {
            "title": {"top": 30, "left": "center", "text": "2016年某人每天的步数"},
            "tooltip": {},
            "visualMap": {
                "min": 0,
                "max": 10000,
                "type": "piecewise",
                "orient": "horizontal",
                "left": "center",
                "top": 65,
                "textStyle": {"color": "#000"},
            },
            "calendar": {
                "top": 120,
                "left": 30,
                "right": 30,
                "cellSize": ["auto", 13],
                "range": "2016",
                "itemStyle": {"borderWidth": 0.5},
                "yearLabel": {"show": False},
            },
            "series": {
                "type": "heatmap",
                "coordinateSystem": "calendar",
                "data": get_virtual_data(2016),
            },
        }
        st_echarts(options)
示例#10
0
def render_map():
    with st.echo("below"):
        options = {
            "backgroundColor": "#404a59",
            "title": {
                "text": "全国主要城市空气质量",
                "subtext": "data from PM25.in",
                "sublink": "http://www.pm25.in",
                "left": "center",
                "textStyle": {"color": "#fff"},
            },
            "tooltip": {"trigger": "item"},
            "legend": {
                "orient": "vertical",
                "top": "bottom",
                "left": "right",
                "data": ["pm2.5"],
                "textStyle": {"color": "#fff"},
            },
            "visualMap": {
                "min": 0,
                "max": 300,
                "splitNumber": 5,
                "color": ["#d94e5d", "#eac736", "#50a3ba"],
                "textStyle": {"color": "#fff"},
            },
            "geo": {
                "map": "china",
                "label": {"emphasis": {"show": False}},
                "itemStyle": {
                    "normal": {"areaColor": "#323c48", "borderColor": "#111"},
                    "emphasis": {"areaColor": "#2a333d"},
                },
            },
        }
        st_echarts(options)
示例#11
0
def render_scatter_simple():
    options = {
        "xAxis": {},
        "yAxis": {},
        "series": [{
            "symbolSize":
            20,
            "data": [
                [10.0, 8.04],
                [8.07, 6.95],
                [13.0, 7.58],
                [9.05, 8.81],
                [11.0, 8.33],
                [14.0, 7.66],
                [13.4, 6.81],
                [10.0, 6.33],
                [14.0, 8.96],
                [12.5, 6.82],
                [9.15, 7.20],
                [11.5, 7.20],
                [3.03, 4.23],
                [12.2, 7.83],
                [2.02, 4.47],
                [1.05, 3.33],
                [4.05, 4.96],
                [6.03, 7.24],
                [12.0, 6.26],
                [12.0, 8.84],
                [7.08, 5.82],
                [5.02, 5.68],
            ],
            "type":
            "scatter",
        }],
    }
    st_echarts(options=options, height="500px")
示例#12
0
def render_scatter_single_axis():
    hours = [
        "12a",
        "1a",
        "2a",
        "3a",
        "4a",
        "5a",
        "6a",
        "7a",
        "8a",
        "9a",
        "10a",
        "11a",
        "12p",
        "1p",
        "2p",
        "3p",
        "4p",
        "5p",
        "6p",
        "7p",
        "8p",
        "9p",
        "10p",
        "11p",
    ]
    days = [
        "Saturday",
        "Friday",
        "Thursday",
        "Wednesday",
        "Tuesday",
        "Monday",
        "Sunday",
    ]
    data = [
        [0, 0, 5],
        [0, 1, 1],
        [0, 2, 0],
        [0, 3, 0],
        [0, 4, 0],
        [0, 5, 0],
        [0, 6, 0],
        [0, 7, 0],
        [0, 8, 0],
        [0, 9, 0],
        [0, 10, 0],
        [0, 11, 2],
        [0, 12, 4],
        [0, 13, 1],
        [0, 14, 1],
        [0, 15, 3],
        [0, 16, 4],
        [0, 17, 6],
        [0, 18, 4],
        [0, 19, 4],
        [0, 20, 3],
        [0, 21, 3],
        [0, 22, 2],
        [0, 23, 5],
        [1, 0, 7],
        [1, 1, 0],
        [1, 2, 0],
        [1, 3, 0],
        [1, 4, 0],
        [1, 5, 0],
        [1, 6, 0],
        [1, 7, 0],
        [1, 8, 0],
        [1, 9, 0],
        [1, 10, 5],
        [1, 11, 2],
        [1, 12, 2],
        [1, 13, 6],
        [1, 14, 9],
        [1, 15, 11],
        [1, 16, 6],
        [1, 17, 7],
        [1, 18, 8],
        [1, 19, 12],
        [1, 20, 5],
        [1, 21, 5],
        [1, 22, 7],
        [1, 23, 2],
        [2, 0, 1],
        [2, 1, 1],
        [2, 2, 0],
        [2, 3, 0],
        [2, 4, 0],
        [2, 5, 0],
        [2, 6, 0],
        [2, 7, 0],
        [2, 8, 0],
        [2, 9, 0],
        [2, 10, 3],
        [2, 11, 2],
        [2, 12, 1],
        [2, 13, 9],
        [2, 14, 8],
        [2, 15, 10],
        [2, 16, 6],
        [2, 17, 5],
        [2, 18, 5],
        [2, 19, 5],
        [2, 20, 7],
        [2, 21, 4],
        [2, 22, 2],
        [2, 23, 4],
        [3, 0, 7],
        [3, 1, 3],
        [3, 2, 0],
        [3, 3, 0],
        [3, 4, 0],
        [3, 5, 0],
        [3, 6, 0],
        [3, 7, 0],
        [3, 8, 1],
        [3, 9, 0],
        [3, 10, 5],
        [3, 11, 4],
        [3, 12, 7],
        [3, 13, 14],
        [3, 14, 13],
        [3, 15, 12],
        [3, 16, 9],
        [3, 17, 5],
        [3, 18, 5],
        [3, 19, 10],
        [3, 20, 6],
        [3, 21, 4],
        [3, 22, 4],
        [3, 23, 1],
        [4, 0, 1],
        [4, 1, 3],
        [4, 2, 0],
        [4, 3, 0],
        [4, 4, 0],
        [4, 5, 1],
        [4, 6, 0],
        [4, 7, 0],
        [4, 8, 0],
        [4, 9, 2],
        [4, 10, 4],
        [4, 11, 4],
        [4, 12, 2],
        [4, 13, 4],
        [4, 14, 4],
        [4, 15, 14],
        [4, 16, 12],
        [4, 17, 1],
        [4, 18, 8],
        [4, 19, 5],
        [4, 20, 3],
        [4, 21, 7],
        [4, 22, 3],
        [4, 23, 0],
        [5, 0, 2],
        [5, 1, 1],
        [5, 2, 0],
        [5, 3, 3],
        [5, 4, 0],
        [5, 5, 0],
        [5, 6, 0],
        [5, 7, 0],
        [5, 8, 2],
        [5, 9, 0],
        [5, 10, 4],
        [5, 11, 1],
        [5, 12, 5],
        [5, 13, 10],
        [5, 14, 5],
        [5, 15, 7],
        [5, 16, 11],
        [5, 17, 6],
        [5, 18, 0],
        [5, 19, 5],
        [5, 20, 3],
        [5, 21, 4],
        [5, 22, 2],
        [5, 23, 0],
        [6, 0, 1],
        [6, 1, 0],
        [6, 2, 0],
        [6, 3, 0],
        [6, 4, 0],
        [6, 5, 0],
        [6, 6, 0],
        [6, 7, 0],
        [6, 8, 0],
        [6, 9, 0],
        [6, 10, 1],
        [6, 11, 0],
        [6, 12, 2],
        [6, 13, 1],
        [6, 14, 3],
        [6, 15, 4],
        [6, 16, 0],
        [6, 17, 0],
        [6, 18, 0],
        [6, 19, 0],
        [6, 20, 1],
        [6, 21, 2],
        [6, 22, 2],
        [6, 23, 6],
    ]

    option = {
        "tooltip": {
            "position": "top"
        },
        "title": [{
            "textBaseline": "middle",
            "top": f"{(idx + 0.5) * 100 / 7}%",
            "text": day
        } for idx, day in enumerate(days)],
        "singleAxis": [{
            "left": 150,
            "type": "category",
            "boundaryGap": False,
            "data": hours,
            "top": f"{(idx * 100 / 7 + 5)}%",
            "height": f"{(100 / 7 - 10)}%",
            "axisLabel": {
                "interval": 2
            },
        } for idx, _ in enumerate(days)],
        "series": [{
            "singleAxisIndex":
            idx,
            "coordinateSystem":
            "singleAxis",
            "type":
            "scatter",
            "data": [],
            "symbolSize":
            JsCode("function(dataItem){return dataItem[1]*4}").js_code,
        } for idx, _ in enumerate(days)],
    }
    for dataItem in data:
        option["series"][dataItem[0]]["data"].append(
            [dataItem[1], dataItem[2]])
    st_echarts(options=option, height="600px")
示例#13
0
st.markdown("---")
# top = st.slider('Select year of interest:',min_value=10,max_value=30,value=20)
st.markdown("### An overview")
st.image(im5, use_column_width=True)
top = 25
htmap, bar, country_list = get_overall(top)
st.plotly_chart(bar, use_container_width=True)
st.image(im6, use_column_width=True)
st.plotly_chart(htmap, use_container_width=True)

st.markdown("### Country's medal in discipline over year")
st.image(im7, use_column_width=True)
country = st.selectbox('Choose the country you want to explore:', country_list)
st.write("Performance by year of ", country)
options = get_domain_plot(country)
st_echarts(options=options, height="600px")
st.image(im4, use_column_width=True)

st.markdown("### Performance in each sports")
st.image(im8, use_column_width=True)
options_sample = get_sample()
st_echarts(options=options_sample, height="500px")

st.markdown("# The wealthier, the better?")
st.markdown("---")
st.image(im1, use_column_width=True)
gdp_years = [1992, 1994, 1998, 2002, 2006, 2010, 2014]
# the first part: gdp - rank
year = st.slider('', min_value=1994, max_value=2014, step=4)
st.sidebar.markdown("### Customize the score calculation methods here:")
示例#14
0
def render_waterfall_chart():
    options = {
        "title": {
            "text": "阶梯瀑布图",
            "subtext": "From ExcelHome",
            "sublink": "http://e.weibo.com/1341556070/Aj1J2x5a5",
        },
        "tooltip": {
            "trigger":
            "axis",
            "axisPointer": {
                "type": "shadow"
            },
            "formatter":
            JsCode(
                "function(params){var tar;if(params[1].value!=='-'){tar=params[1]}else{tar=params[0]}return tar.name+'<br/>'+tar.seriesName+' : '+tar.value}"
            ).js_code,
        },
        "legend": {
            "data": ["支出", "收入"]
        },
        "grid": {
            "left": "3%",
            "right": "4%",
            "bottom": "3%",
            "containLabel": True
        },
        "xAxis": {
            "type": "category",
            "splitLine": {
                "show": False
            },
            "data": [f"11月 {i} 日" for i in range(1, 12)],
        },
        "yAxis": {
            "type": "value"
        },
        "series": [
            {
                "name":
                "辅助",
                "type":
                "bar",
                "stack":
                "总量",
                "itemStyle": {
                    "barBorderColor": "rgba(0,0,0,0)",
                    "color": "rgba(0,0,0,0)",
                },
                "emphasis": {
                    "itemStyle": {
                        "barBorderColor": "rgba(0,0,0,0)",
                        "color": "rgba(0,0,0,0)",
                    }
                },
                "data":
                [0, 900, 1245, 1530, 1376, 1376, 1511, 1689, 1856, 1495, 1292],
            },
            {
                "name": "收入",
                "type": "bar",
                "stack": "总量",
                "label": {
                    "show": True,
                    "position": "top"
                },
                "data":
                [900, 345, 393, "-", "-", 135, 178, 286, "-", "-", "-"],
            },
            {
                "name": "支出",
                "type": "bar",
                "stack": "总量",
                "label": {
                    "show": True,
                    "position": "bottom"
                },
                "data":
                ["-", "-", "-", 108, 154, "-", "-", "-", 119, 361, 203],
            },
        ],
    }
    st_echarts(options=options, height="500px")
示例#15
0
def render_stacked_horizontal_bar():
    options = {
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "shadow"
            }
        },
        "legend": {
            "data":
            ["Direct", "Mail Ad", "Affiliate Ad", "Video Ad", "Search Engine"]
        },
        "grid": {
            "left": "3%",
            "right": "4%",
            "bottom": "3%",
            "containLabel": True
        },
        "xAxis": {
            "type": "value"
        },
        "yAxis": {
            "type": "category",
            "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        "series": [
            {
                "name": "Direct",
                "type": "bar",
                "stack": "total",
                "label": {
                    "show": True
                },
                "emphasis": {
                    "focus": "series"
                },
                "data": [320, 302, 301, 334, 390, 330, 320],
            },
            {
                "name": "Mail Ad",
                "type": "bar",
                "stack": "total",
                "label": {
                    "show": True
                },
                "emphasis": {
                    "focus": "series"
                },
                "data": [120, 132, 101, 134, 90, 230, 210],
            },
            {
                "name": "Affiliate Ad",
                "type": "bar",
                "stack": "total",
                "label": {
                    "show": True
                },
                "emphasis": {
                    "focus": "series"
                },
                "data": [220, 182, 191, 234, 290, 330, 310],
            },
            {
                "name": "Video Ad",
                "type": "bar",
                "stack": "total",
                "label": {
                    "show": True
                },
                "emphasis": {
                    "focus": "series"
                },
                "data": [150, 212, 201, 154, 190, 330, 410],
            },
            {
                "name": "Search Engine",
                "type": "bar",
                "stack": "total",
                "label": {
                    "show": True
                },
                "emphasis": {
                    "focus": "series"
                },
                "data": [820, 832, 901, 934, 1290, 1330, 1320],
            },
        ],
    }
    st_echarts(options=options, height="500px")
示例#16
0
def render_wordcloud():
    with st.echo("below"):
        options = {
            "tooltip": {},
            "series": [
                {
                    "type": "wordCloud",
                    "gridSize": 2,
                    "sizeRange": [12, 50],
                    "rotationRange": [-90, 90],
                    "shape": "pentagon",
                    "width": 600,
                    "height": 400,
                    "drawOutOfBound": True,
                    "emphasis": {
                        "textStyle": {"shadowBlur": 10, "shadowColor": "#333"}
                    },
                    "data": [
                        {
                            "name": "Sam S Club",
                            "value": 10000,
                            "textStyle": {"color": "black"},
                            "emphasis": {"textStyle": {"color": "red"}},
                        },
                        {"name": "Macys", "value": 6181},
                        {"name": "Amy Schumer", "value": 4386},
                        {"name": "Jurassic World", "value": 4055},
                        {"name": "Charter Communications", "value": 2467},
                        {"name": "Chick Fil A", "value": 2244},
                        {"name": "Planet Fitness", "value": 1898},
                        {"name": "Pitch Perfect", "value": 1484},
                        {"name": "Express", "value": 1112},
                        {"name": "Home", "value": 965},
                        {"name": "Johnny Depp", "value": 847},
                        {"name": "Lena Dunham", "value": 582},
                        {"name": "Lewis Hamilton", "value": 555},
                        {"name": "KXAN", "value": 550},
                        {"name": "Mary Ellen Mark", "value": 462},
                        {"name": "Farrah Abraham", "value": 366},
                        {"name": "Rita Ora", "value": 360},
                        {"name": "Serena Williams", "value": 282},
                        {"name": "NCAA baseball tournament", "value": 273},
                        {"name": "Point Break", "value": 265},
                    ],
                }
            ],
        }
        st_echarts(options)

        data = [
            ("生活资源", "999"),
            ("供热管理", "888"),
            ("供气质量", "777"),
            ("生活用水管理", "688"),
            ("一次供水问题", "588"),
            ("交通运输", "516"),
            ("城市交通", "515"),
            ("环境保护", "483"),
            ("房地产管理", "462"),
            ("城乡建设", "449"),
            ("社会保障与福利", "429"),
            ("社会保障", "407"),
            ("文体与教育管理", "406"),
            ("公共安全", "406"),
            ("公交运输管理", "386"),
            ("出租车运营管理", "385"),
            ("供热管理", "375"),
            ("市容环卫", "355"),
            ("自然资源管理", "355"),
            ("粉尘污染", "335"),
            ("噪声污染", "324"),
            ("土地资源管理", "304"),
            ("物业服务与管理", "304"),
            ("医疗卫生", "284"),
            ("粉煤灰污染", "284"),
            ("占道", "284"),
            ("供热发展", "254"),
            ("农村土地规划管理", "254"),
            ("生活噪音", "253"),
            ("供热单位影响", "253"),
            ("城市供电", "223"),
            ("房屋质量与安全", "223"),
            ("大气污染", "223"),
            ("房屋安全", "223"),
            ("文化活动", "223"),
            ("拆迁管理", "223"),
            ("公共设施", "223"),
            ("供气质量", "223"),
            ("供电管理", "223"),
            ("燃气管理", "152"),
            ("教育管理", "152"),
            ("医疗纠纷", "152"),
            ("执法监督", "152"),
            ("设备安全", "152"),
            ("政务建设", "152"),
            ("县区、开发区", "152"),
            ("宏观经济", "152"),
            ("教育管理", "112"),
            ("社会保障", "112"),
            ("生活用水管理", "112"),
            ("物业服务与管理", "112"),
            ("分类列表", "112"),
            ("农业生产", "112"),
            ("二次供水问题", "112"),
            ("城市公共设施", "92"),
            ("拆迁政策咨询", "92"),
            ("物业服务", "92"),
            ("物业管理", "92"),
            ("社会保障保险管理", "92"),
            ("低保管理", "92"),
            ("文娱市场管理", "72"),
            ("城市交通秩序管理", "72"),
            ("执法争议", "72"),
            ("商业烟尘污染", "72"),
            ("占道堆放", "71"),
            ("地上设施", "71"),
            ("水质", "71"),
            ("无水", "71"),
            ("供热单位影响", "71"),
            ("人行道管理", "71"),
            ("主网原因", "71"),
            ("集中供热", "71"),
            ("客运管理", "71"),
            ("国有公交(大巴)管理", "71"),
            ("工业粉尘污染", "71"),
            ("治安案件", "71"),
            ("压力容器安全", "71"),
            ("身份证管理", "71"),
            ("群众健身", "41"),
            ("工业排放污染", "41"),
            ("破坏森林资源", "41"),
            ("市场收费", "41"),
            ("生产资金", "41"),
            ("生产噪声", "41"),
            ("农村低保", "41"),
            ("劳动争议", "41"),
            ("劳动合同争议", "41"),
            ("劳动报酬与福利", "41"),
            ("医疗事故", "21"),
            ("停供", "21"),
            ("基础教育", "21"),
            ("职业教育", "21"),
            ("物业资质管理", "21"),
            ("拆迁补偿", "21"),
            ("设施维护", "21"),
            ("市场外溢", "11"),
            ("占道经营", "11"),
            ("树木管理", "11"),
            ("农村基础设施", "11"),
            ("无水", "11"),
            ("供气质量", "11"),
            ("停气", "11"),
            ("市政府工作部门(含部门管理机构、直属单位)", "11"),
            ("燃气管理", "11"),
            ("市容环卫", "11"),
            ("新闻传媒", "11"),
            ("人才招聘", "11"),
            ("市场环境", "11"),
            ("行政事业收费", "11"),
            ("食品安全与卫生", "11"),
            ("城市交通", "11"),
            ("房地产开发", "11"),
            ("房屋配套问题", "11"),
            ("物业服务", "11"),
            ("物业管理", "11"),
            ("占道", "11"),
            ("园林绿化", "11"),
            ("户籍管理及身份证", "11"),
            ("公交运输管理", "11"),
            ("公路(水路)交通", "11"),
            ("房屋与图纸不符", "11"),
            ("有线电视", "11"),
            ("社会治安", "11"),
            ("林业资源", "11"),
            ("其他行政事业收费", "11"),
            ("经营性收费", "11"),
            ("食品安全与卫生", "11"),
            ("体育活动", "11"),
            ("有线电视安装及调试维护", "11"),
            ("低保管理", "11"),
            ("劳动争议", "11"),
            ("社会福利及事务", "11"),
            ("一次供水问题", "11"),
        ]

        c = (
            WordCloud()
            .add(series_name="热点分析", data_pair=data, word_size_range=[6, 66])
            .set_global_opts(
                title_opts=opts.TitleOpts(
                    title="热点分析", title_textstyle_opts=opts.TextStyleOpts(font_size=23)
                ),
                tooltip_opts=opts.TooltipOpts(is_show=True),
            )
        )
        st_pyecharts(c)
示例#17
0
def render_nightingale_rose_diagram():
    option = {
        "legend": {
            "top": "bottom"
        },
        "toolbox": {
            "show": True,
            "feature": {
                "mark": {
                    "show": True
                },
                "dataView": {
                    "show": True,
                    "readOnly": False
                },
                "restore": {
                    "show": True
                },
                "saveAsImage": {
                    "show": True
                },
            },
        },
        "series": [{
            "name":
            "面积模式",
            "type":
            "pie",
            "radius": [50, 250],
            "center": ["50%", "50%"],
            "roseType":
            "area",
            "itemStyle": {
                "borderRadius": 8
            },
            "data": [
                {
                    "value": 40,
                    "name": "rose 1"
                },
                {
                    "value": 38,
                    "name": "rose 2"
                },
                {
                    "value": 32,
                    "name": "rose 3"
                },
                {
                    "value": 30,
                    "name": "rose 4"
                },
                {
                    "value": 28,
                    "name": "rose 5"
                },
                {
                    "value": 26,
                    "name": "rose 6"
                },
                {
                    "value": 22,
                    "name": "rose 7"
                },
                {
                    "value": 18,
                    "name": "rose 8"
                },
            ],
        }],
    }
    st_echarts(
        options=option,
        height="600px",
    )
示例#18
0
            "label": {
                "position": "right",
                "verticalAlign": "middle",
                "align": "left",
            }
        },
        "expandAndCollapse": True,
        "animationDuration": 550,
        "animationDurationUpdate": 750,
    }],
}

st.markdown('### **⬇️ Interactive Tree View  **')
st.markdown('*Right-click to save Tree View as .jpeg* 📷')

st_echarts(opts, height=1000)

st.markdown('### **⬇️ Table View  **')

edges = edges.reset_index(drop=True)

st.dataframe(edges, width=1700, height=1000)

import matplotlib as plt
import seaborn as sns

cm = sns.light_palette("green", as_cmap=True)
#edgescoloured = edges.style.background_gradient(cmap=cm)
edgescoloured = edges.style.background_gradient(cmap='Blues')

#format_dictionary = {
示例#19
0
def render_pie_donutradius():
    options = {
        "tooltip": {
            "trigger": "item"
        },
        "legend": {
            "top": "5%",
            "left": "center"
        },
        "series": [{
            "name":
            "访问来源",
            "type":
            "pie",
            "radius": ["40%", "70%"],
            "avoidLabelOverlap":
            False,
            "itemStyle": {
                "borderRadius": 10,
                "borderColor": "#fff",
                "borderWidth": 2,
            },
            "label": {
                "show": False,
                "position": "center"
            },
            "emphasis": {
                "label": {
                    "show": True,
                    "fontSize": "40",
                    "fontWeight": "bold"
                }
            },
            "labelLine": {
                "show": False
            },
            "data": [
                {
                    "value": 1048,
                    "name": "搜索引擎"
                },
                {
                    "value": 735,
                    "name": "直接访问"
                },
                {
                    "value": 580,
                    "name": "邮件营销"
                },
                {
                    "value": 484,
                    "name": "联盟广告"
                },
                {
                    "value": 300,
                    "name": "视频广告"
                },
            ],
        }],
    }
    st_echarts(
        options=options,
        height="500px",
    )
示例#20
0
def main():
    st.sidebar.title("Stream Vis")
    st.sidebar.markdown("""
        Streamlit Visualization using Echart 
    """)
    try:
        df = fileUpload()
        st.sidebar.markdown("""---""")
        st.write(df)
        option = selectVisual()
        if option == "Bar":
            data = form.bar(df)
            if st.button('Generate Bar'):
                opt = Visual.barchart(df, data['show'], data['by'],
                                      data['andby'], data['orientation'],
                                      data['title'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt)
        elif option == "Line":
            data = form.line(df)
            if st.button('Generate Line'):
                opt = Visual.line(df, data['show'], data['by'], data['andby'],
                                  data['title'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt)
        elif option == "Pie":
            data = form.pie(df)
            if st.button("Generate Pie"):
                opt = Visual.pie(df, data['show'], data['by'], data['title'],
                                 data['doughnut'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt)
        elif option == "Scatter":
            data = form.scatter(df)
            if st.button("Generate Scatter"):
                opt = Visual.scatter(df, data['x'], data['y'], data['group'],
                                     data['title'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt)
        elif option == "Box":
            data = form.boxplot(df)
            if st.button("Generate Box"):
                opt = Visual.boxplot(df, data['show'], data['by'],
                                     data['orientation'], data['title'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt['option'])
        elif option == "Heatmap":
            data = form.heatmap(df)
            if st.button('Generate Heatmap'):
                opt = Visual.heatmap(df, data['x'], data['y'], data['value'],
                                     data['title'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt)
        elif option == "Histogram":
            data = form.histogram(df)
            if st.button("Generate Histogram"):
                opt = Visual.histogram(df, data['show'], data['title'])
                opt['color'] = colormap_check(data['color'])
                st_echarts(opt)

        elif option == "Map":
            data = form.geomap(df)
            st.echo(data)
            if st.button("Generate Map"):
                opt = Visual.geomap(df, data["region"], data["value"],
                                    data["map_title"], data["title"])
                if data['map'] == "jakarta":
                    with open("lib/jakarta.json", "r") as f:
                        map = Map(data["map_title"], json.loads(f.read()))
                elif data['map'] == "jogja":
                    with open("lib/jogja.json", "r") as f:
                        map = Map(data["map_title"], json.loads(f.read()))

                st_echarts(opt, map=map)
        elif option == "Radar":
            data = form.radar(df)
            if st.button("Generate Radar"):
                opt = Visual.radar(df, data["show"], data["by"], data["title"],
                                   data["method"])
                st.echo(opt)
                st_echarts(opt)
        else:
            if st.button("Generate"):
                opts = Visual.auto_generator(df)
                for x in opts:
                    st_echarts(x)

    except:
        st.markdown("""
            There is no dataset
        """)
示例#21
0
def main():
    st.title('Votes for women MPs - UK')
    df = load_data(full_spreadsheet=False).transpose()
    series_data = []

    for r in df:
        election_data = list(df[r])
        series_data.append({
            'type': 'bar',
            'stack': 'total',
            'label': {
                'show': False
            },
            'emphasis': {
                'focus': 'opacity'
            },
            'data': election_data
        })
    xaxis_data = list(df.index)
    options = {
        'grid': {
            'left': '3%',
            'right': '4%',
            'bottom': '3%',
            'containLabel': True
        },
        'yAxis': {
            'type': 'value'
        },
        'xAxis': {
            'type': 'category',
            'axisLabel': {
                'show': True,
                'rotate': 45
            },
            'data': [1]
        },
        'dataZoom': [{
            'show': True,
            'start': 0,
            'end': 50
        }, {
            'type': 'inside',
            'start': 0,
            'end': 20
        }],
        'series': [
            {
                'type': 'bar',
                'stack': 'total',
                'label': {
                    'show': True
                },
                'emphasis': {
                    'focus': 'opacity'
                },
                'data': []
            },
        ]
    }
    options['series'] = series_data
    options['xAxis']['data'] = xaxis_data
    theme = {
        'color': [
            '#d87c7c', '#919e8b', '#d7ab82', '#6e7074', '#61a0a8', '#efa18d',
            '#787464', '#cc7e63', '#724e58', '#4b565b'
        ],
        'backgroundColor':
        'rgba(254,248,239,1)',
        'textStyle': {},
        'title': {
            'textStyle': {
                'color': '#333333'
            },
            'subtextStyle': {
                'color': '#aaaaaa'
            }
        },
        'line': {
            'itemStyle': {
                'borderWidth': 1
            },
            'lineStyle': {
                'width': 2
            },
            'symbolSize': 4,
            'symbol': 'emptyCircle',
            'smooth': False
        },
        'radar': {
            'itemStyle': {
                'borderWidth': 1
            },
            'lineStyle': {
                'width': 2
            },
            'symbolSize': 4,
            'symbol': 'emptyCircle',
            'smooth': False
        },
        'bar': {
            'itemStyle': {
                'barBorderWidth': 0,
                'barBorderColor': '#ccc'
            }
        },
        'pie': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'scatter': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'boxplot': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'parallel': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'sankey': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'funnel': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'gauge': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            }
        },
        'candlestick': {
            'itemStyle': {
                'color': '#c23531',
                'color0': '#314656',
                'borderColor': '#c23531',
                'borderColor0': '#314656',
                'borderWidth': 1
            }
        },
        'graph': {
            'itemStyle': {
                'borderWidth': 0,
                'borderColor': '#ccc'
            },
            'lineStyle': {
                'width': 1,
                'color': '#aaa'
            },
            'symbolSize':
            4,
            'symbol':
            'emptyCircle',
            'smooth':
            False,
            'color': [
                '#d87c7c', '#919e8b', '#d7ab82', '#6e7074', '#61a0a8',
                '#efa18d', '#787464', '#cc7e63', '#724e58', '#4b565b'
            ],
            'label': {
                'color': '#eee'
            }
        },
        'map': {
            'itemStyle': {
                'normal': {
                    'areaColor': '#eeeeee',
                    'borderColor': '#444444',
                    'borderWidth': 0.5
                },
                'emphasis': {
                    'areaColor': 'rgba(255,215,0,0.8)',
                    'borderColor': '#444444',
                    'borderWidth': 1
                }
            },
            'label': {
                'normal': {
                    'textStyle': {
                        'color': '#000000'
                    }
                },
                'emphasis': {
                    'textStyle': {
                        'color': 'rgb(100,0,0)'
                    }
                }
            }
        },
        'geo': {
            'itemStyle': {
                'normal': {
                    'areaColor': '#eeeeee',
                    'borderColor': '#444444',
                    'borderWidth': 0.5
                },
                'emphasis': {
                    'areaColor': 'rgba(255,215,0,0.8)',
                    'borderColor': '#444444',
                    'borderWidth': 1
                }
            },
            'label': {
                'normal': {
                    'textStyle': {
                        'color': '#000000'
                    }
                },
                'emphasis': {
                    'textStyle': {
                        'color': 'rgb(100,0,0)'
                    }
                }
            }
        },
        'categoryAxis': {
            'axisLine': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisTick': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisLabel': {
                'show': True,
                'textStyle': {
                    'color': '#333'
                }
            },
            'splitLine': {
                'show': False,
                'lineStyle': {
                    'color': ['#ccc']
                }
            },
            'splitArea': {
                'show': False,
                'areaStyle': {
                    'color':
                    ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
                }
            }
        },
        'valueAxis': {
            'axisLine': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisTick': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisLabel': {
                'show': True,
                'textStyle': {
                    'color': '#333'
                }
            },
            'splitLine': {
                'show': True,
                'lineStyle': {
                    'color': ['#ccc']
                }
            },
            'splitArea': {
                'show': False,
                'areaStyle': {
                    'color':
                    ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
                }
            }
        },
        'logAxis': {
            'axisLine': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisTick': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisLabel': {
                'show': True,
                'textStyle': {
                    'color': '#333'
                }
            },
            'splitLine': {
                'show': True,
                'lineStyle': {
                    'color': ['#ccc']
                }
            },
            'splitArea': {
                'show': False,
                'areaStyle': {
                    'color':
                    ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
                }
            }
        },
        'timeAxis': {
            'axisLine': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisTick': {
                'show': True,
                'lineStyle': {
                    'color': '#333'
                }
            },
            'axisLabel': {
                'show': True,
                'textStyle': {
                    'color': '#333'
                }
            },
            'splitLine': {
                'show': True,
                'lineStyle': {
                    'color': ['#ccc']
                }
            },
            'splitArea': {
                'show': False,
                'areaStyle': {
                    'color':
                    ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
                }
            }
        },
        'toolbox': {
            'iconStyle': {
                'normal': {
                    'borderColor': '#999999'
                },
                'emphasis': {
                    'borderColor': '#666666'
                }
            }
        },
        'legend': {
            'textStyle': {
                'color': '#333333'
            }
        },
        'tooltip': {
            'axisPointer': {
                'lineStyle': {
                    'color': '#cccccc',
                    'width': 1
                },
                'crossStyle': {
                    'color': '#cccccc',
                    'width': 1
                }
            }
        },
        'timeline': {
            'lineStyle': {
                'color': '#293c55',
                'width': 1
            },
            'itemStyle': {
                'normal': {
                    'color': '#293c55',
                    'borderWidth': 1
                },
                'emphasis': {
                    'color': '#a9334c'
                }
            },
            'controlStyle': {
                'normal': {
                    'color': '#293c55',
                    'borderColor': '#293c55',
                    'borderWidth': 0.5
                },
                'emphasis': {
                    'color': '#293c55',
                    'borderColor': '#293c55',
                    'borderWidth': 0.5
                }
            },
            'checkpointStyle': {
                'color': '#e43c59',
                'borderColor': '#c23531'
            },
            'label': {
                'normal': {
                    'textStyle': {
                        'color': '#293c55'
                    }
                },
                'emphasis': {
                    'textStyle': {
                        'color': '#293c55'
                    }
                }
            }
        },
        'visualMap': {
            'color': ['#bf444c', '#d88273', '#f6efa6']
        },
        'dataZoom': {
            'backgroundColor': 'rgba(47,69,84,0)',
            'dataBackgroundColor': 'rgba(47,69,84,0.3)',
            'fillerColor': 'rgba(167,183,204,0.4)',
            'handleColor': '#a7b7cc',
            'handleSize': '100%',
            'textStyle': {
                'color': '#333333'
            }
        },
        'markPoint': {
            'label': {
                'color': '#eee'
            },
            'emphasis': {
                'label': {
                    'color': '#eee'
                }
            }
        }
    }

    st_echarts(options=options, height="600px", theme=theme)
    df = load_data().transpose()
    show_party(df)
    if st.checkbox('Show raw data'):
        st.subheader('Raw data')
        df = load_data(full_spreadsheet=True).transpose()
        st.write(df)
        df = load_data().transpose()
        df = set_column_labels_cut_metadata(df)
        df['total'] = df.sum(axis=1)
        df["total"] = pd.to_numeric(df["total"])
        df.sort_values(by='total', inplace=True, ascending=False)
        df['name'] = df.index
        st.write(df.total)
示例#22
0
                "type": "line",
                "stack": "headcount",
                "label": {
                    "show": True,
                    "position": "top"
                },
                "areaStyle": {},
                "emphasis": {
                    "focus": "series"
                },
                "data": [820, 932, 901, 934, 1290, 1330, 1320],
            },
        ],
    }

    st_echarts(options=options_1, height="400px")

    options_2 = {
        "title": {
            "text": "折线图堆叠"
        },
        "tooltip": {
            "trigger": "axis"
        },
        "legend": {
            "data": ["邮件营销", "联盟广告", "视频广告", "直接访问", "搜索引擎"]
        },
        "grid": {
            "left": "3%",
            "right": "4%",
            "bottom": "3%",
示例#23
0
def render_anscombe_quartet():
    data = [
        [
            [10.0, 8.04],
            [8.0, 6.95],
            [13.0, 7.58],
            [9.0, 8.81],
            [11.0, 8.33],
            [14.0, 9.96],
            [6.0, 7.24],
            [4.0, 4.26],
            [12.0, 10.84],
            [7.0, 4.82],
            [5.0, 5.68],
        ],
        [
            [10.0, 9.14],
            [8.0, 8.14],
            [13.0, 8.74],
            [9.0, 8.77],
            [11.0, 9.26],
            [14.0, 8.10],
            [6.0, 6.13],
            [4.0, 3.10],
            [12.0, 9.13],
            [7.0, 7.26],
            [5.0, 4.74],
        ],
        [
            [10.0, 7.46],
            [8.0, 6.77],
            [13.0, 12.74],
            [9.0, 7.11],
            [11.0, 7.81],
            [14.0, 8.84],
            [6.0, 6.08],
            [4.0, 5.39],
            [12.0, 8.15],
            [7.0, 6.42],
            [5.0, 5.73],
        ],
        [
            [8.0, 6.58],
            [8.0, 5.76],
            [8.0, 7.71],
            [8.0, 8.84],
            [8.0, 8.47],
            [8.0, 7.04],
            [8.0, 5.25],
            [19.0, 12.50],
            [8.0, 5.56],
            [8.0, 7.91],
            [8.0, 6.89],
        ],
    ]

    line_opt = {
        "animation":
        False,
        "label": {
            "formatter": "y = 0.5 * x + 3",
            "align": "right"
        },
        "lineStyle": {
            "type": "solid"
        },
        "tooltip": {
            "formatter": "y = 0.5 * x + 3"
        },
        "data": [[{
            "coord": [0, 3],
            "symbol": None
        }, {
            "coord": [20, 13],
            "symbol": None
        }]],
    }

    option = {
        "title": {
            "text": "Anscombe's quartet",
            "left": "center",
            "top": 0
        },
        "grid": [
            {
                "left": "7%",
                "top": "7%",
                "width": "38%",
                "height": "38%"
            },
            {
                "right": "7%",
                "top": "7%",
                "width": "38%",
                "height": "38%"
            },
            {
                "left": "7%",
                "bottom": "7%",
                "width": "38%",
                "height": "38%"
            },
            {
                "right": "7%",
                "bottom": "7%",
                "width": "38%",
                "height": "38%"
            },
        ],
        "tooltip": {
            "formatter": "Group {a}: ({c})"
        },
        "xAxis": [
            {
                "gridIndex": 0,
                "min": 0,
                "max": 20
            },
            {
                "gridIndex": 1,
                "min": 0,
                "max": 20
            },
            {
                "gridIndex": 2,
                "min": 0,
                "max": 20
            },
            {
                "gridIndex": 3,
                "min": 0,
                "max": 20
            },
        ],
        "yAxis": [
            {
                "gridIndex": 0,
                "min": 0,
                "max": 15
            },
            {
                "gridIndex": 1,
                "min": 0,
                "max": 15
            },
            {
                "gridIndex": 2,
                "min": 0,
                "max": 15
            },
            {
                "gridIndex": 3,
                "min": 0,
                "max": 15
            },
        ],
        "series": [
            {
                "name": "I",
                "type": "scatter",
                "xAxisIndex": 0,
                "yAxisIndex": 0,
                "data": data[0],
                "markLine": line_opt,
            },
            {
                "name": "II",
                "type": "scatter",
                "xAxisIndex": 1,
                "yAxisIndex": 1,
                "data": data[1],
                "markLine": line_opt,
            },
            {
                "name": "III",
                "type": "scatter",
                "xAxisIndex": 2,
                "yAxisIndex": 2,
                "data": data[2],
                "markLine": line_opt,
            },
            {
                "name": "IV",
                "type": "scatter",
                "xAxisIndex": 3,
                "yAxisIndex": 3,
                "data": data[3],
                "markLine": line_opt,
            },
        ],
    }
    st_echarts(options=option, height="600px")
def mlp_regression_interface(dataset_df, dataset_column):
    selected_features = st.sidebar.multiselect(
        "Choose Features as predictor : ", list(dataset_column),
        list(dataset_column))
    if not selected_features:
        st.sidebar.error("Please select at least one feature")

    st.sidebar.write("## Method Parameter")

    activation_type = ['identity', 'logistic', 'tanh', 'relu']
    solver_type = ['lbfgs', 'sgd', 'adam']

    hidden_layer_str = st.sidebar.text_input("Hidden layer ",
                                             value="10,10",
                                             max_chars=20)
    hidden_layer = tuple(map(int, hidden_layer_str.split(',')))
    activation = st.sidebar.selectbox("activation function ",
                                      activation_type,
                                      index=3)
    solver = st.sidebar.selectbox("solver ", solver_type, index=2)
    alpha = st.sidebar.number_input("alpha ", value=0.0001)
    learning_rate = st.sidebar.number_input("learning rate ", value=0.001)
    max_iter = st.sidebar.number_input("maximum iteration ",
                                       value=200,
                                       min_value=1,
                                       step=1)
    early_stopping = st.sidebar.checkbox("early stopping ", value=False)

    not_selected_features = [
        feature for feature in dataset_column
        if feature not in selected_features
    ]
    target = st.sidebar.selectbox("Choose Target column : ",
                                  not_selected_features)

    is_run = st.sidebar.button("Run")
    is_feature_target = selected_features and target

    if is_run and is_feature_target:
        #Preprocessing
        dp = DataPreparation(dataframe=dataset_df,
                             selected_features=selected_features,
                             target=target)
        class_name = dp.get_class_names()
        X_train, X_valid, y_train, y_valid = dp.data_modeling()

        #Modeling
        regre = MLP_Regression(hidden_layer_sizes=hidden_layer,
                               activation=activation,
                               solver=solver,
                               alpha=alpha,
                               learning_rate_init=learning_rate,
                               max_iter=max_iter,
                               early_stopping=early_stopping)
        y_pred = regre.modeling(X_train, X_valid, y_train, y_valid)

        #Metric Evaluation
        rmse, mae, r2 = regre.metircs_model(y_valid, y_pred, class_name)

        #Interpretation
        fi_score = regre.feature_importance(X_valid, y_valid,
                                            selected_features)

        #Interface
        st.write('## **Metrics**')

        st.write('### **Main Metrics**')
        st.write(f'RMSE Score : {rmse}')
        st.write(f'MAE Score : {mae}')
        st.write(f'R Squared Score : {r2}')

        st.write('## **Interpretation**')
        fi_plot_options = feature_importance_plot(fi_score)
        st_echarts(fi_plot_options)
    else:
        st.sidebar.error("Please fill all method parameter")
示例#25
0
def render_mixed_line_bar():
    with st.echo("below"):
        options = {
            "tooltip": {
                "trigger": "axis",
                "axisPointer": {"type": "cross", "crossStyle": {"color": "#999"}},
            },
            "toolbox": {
                "feature": {
                    "dataView": {"show": True, "readOnly": False},
                    "magicType": {"show": True, "type": ["line", "bar"]},
                    "restore": {"show": True},
                    "saveAsImage": {"show": True},
                }
            },
            "legend": {"data": ["蒸发量", "降水量", "平均温度"]},
            "xAxis": [
                {
                    "type": "category",
                    "data": [
                        "1月",
                        "2月",
                        "3月",
                        "4月",
                        "5月",
                        "6月",
                        "7月",
                        "8月",
                        "9月",
                        "10月",
                        "11月",
                        "12月",
                    ],
                    "axisPointer": {"type": "shadow"},
                }
            ],
            "yAxis": [
                {
                    "type": "value",
                    "name": "水量",
                    "min": 0,
                    "max": 250,
                    "interval": 50,
                    "axisLabel": {"formatter": "{value} ml"},
                },
                {
                    "type": "value",
                    "name": "温度",
                    "min": 0,
                    "max": 25,
                    "interval": 5,
                    "axisLabel": {"formatter": "{value} °C"},
                },
            ],
            "series": [
                {
                    "name": "蒸发量",
                    "type": "bar",
                    "data": [
                        2.0,
                        4.9,
                        7.0,
                        23.2,
                        25.6,
                        76.7,
                        135.6,
                        162.2,
                        32.6,
                        20.0,
                        6.4,
                        3.3,
                    ],
                },
                {
                    "name": "降水量",
                    "type": "bar",
                    "data": [
                        2.6,
                        5.9,
                        9.0,
                        26.4,
                        28.7,
                        70.7,
                        175.6,
                        182.2,
                        48.7,
                        18.8,
                        6.0,
                        2.3,
                    ],
                },
                {
                    "name": "平均温度",
                    "type": "line",
                    "yAxisIndex": 1,
                    "data": [
                        2.0,
                        2.2,
                        3.3,
                        4.5,
                        6.3,
                        10.2,
                        20.3,
                        23.4,
                        23.0,
                        16.5,
                        12.0,
                        6.2,
                    ],
                },
            ],
        }
        st_echarts(options)
def svm_regression_interface(dataset_df, dataset_column):
    selected_features = st.sidebar.multiselect(
        "Choose Features as predictor : ", list(dataset_column),
        list(dataset_column))
    if not selected_features:
        st.sidebar.error("Please select at least one feature")

    st.sidebar.write("## Method Parameter")

    C_range = [1, 10, 100, 1000]
    kernel_type = ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed']

    C = float(st.sidebar.selectbox("C ", C_range, index=0))
    kernel = st.sidebar.selectbox("kernel ", kernel_type)
    degree = st.sidebar.number_input("degree", min_value=1, value=3, step=1)
    gamma = st.sidebar.slider("gamma ",
                              min_value=0.1,
                              max_value=1.0,
                              value=1.0,
                              step=0.01)
    coef0 = st.sidebar.number_input("coef0", min_value=0, value=0)

    not_selected_features = [
        feature for feature in dataset_column
        if feature not in selected_features
    ]
    target = st.sidebar.selectbox("Choose Target column : ",
                                  not_selected_features)

    is_run = st.sidebar.button("Run")
    is_feature_target = selected_features and target

    if is_run and is_feature_target:
        #Preprocessing
        dp = DataPreparation(dataframe=dataset_df,
                             selected_features=selected_features,
                             target=target)
        class_name = dp.get_class_names()
        X_train, X_valid, y_train, y_valid = dp.data_modeling()

        #Modeling
        regre = SVM_Regression(C=C,
                               kernel=kernel,
                               degree=degree,
                               gamma=gamma,
                               coef0=coef0)
        y_pred = regre.modeling(X_train, X_valid, y_train)

        #Metric Evaluation
        rmse, mae, r2 = regre.metircs_model(y_valid, y_pred, class_name)

        #Interpretation
        fi_score = regre.feature_importance(X_valid, y_valid,
                                            selected_features)

        #Interface
        st.write('## **Metrics**')

        st.write('### **Main Metrics**')
        st.write(f'RMSE Score : {rmse}')
        st.write(f'MAE Score : {mae}')
        st.write(f'R Squared Score : {r2}')

        st.write('## **Interpretation**')
        fi_plot_options = feature_importance_plot(fi_score)
        st_echarts(fi_plot_options)
    else:
        st.sidebar.error("Please fill all method parameter")
示例#27
0
def render_themeriver():
    option = {
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "line",
                "lineStyle": {"color": "rgba(0,0,0,0.2)", "width": 1, "type": "solid"},
            },
        },
        "legend": {"data": ["DQ", "TY", "SS", "QG", "SY", "DD"]},
        "singleAxis": {
            "top": 50,
            "bottom": 50,
            "axisTick": {},
            "axisLabel": {},
            "type": "time",
            "axisPointer": {"animation": True, "label": {"show": True}},
            "splitLine": {
                "show": True,
                "lineStyle": {"type": "dashed", "opacity": 0.2},
            },
        },
        "series": [
            {
                "type": "themeRiver",
                "emphasis": {
                    "itemStyle": {"shadowBlur": 20, "shadowColor": "rgba(0, 0, 0, 0.8)"}
                },
                "data": [
                    ["2015/11/08", 10, "DQ"],
                    ["2015/11/09", 15, "DQ"],
                    ["2015/11/10", 35, "DQ"],
                    ["2015/11/11", 38, "DQ"],
                    ["2015/11/12", 22, "DQ"],
                    ["2015/11/13", 16, "DQ"],
                    ["2015/11/14", 7, "DQ"],
                    ["2015/11/15", 2, "DQ"],
                    ["2015/11/16", 17, "DQ"],
                    ["2015/11/17", 33, "DQ"],
                    ["2015/11/18", 40, "DQ"],
                    ["2015/11/19", 32, "DQ"],
                    ["2015/11/20", 26, "DQ"],
                    ["2015/11/21", 35, "DQ"],
                    ["2015/11/22", 40, "DQ"],
                    ["2015/11/23", 32, "DQ"],
                    ["2015/11/24", 26, "DQ"],
                    ["2015/11/25", 22, "DQ"],
                    ["2015/11/26", 16, "DQ"],
                    ["2015/11/27", 22, "DQ"],
                    ["2015/11/28", 10, "DQ"],
                    ["2015/11/08", 35, "TY"],
                    ["2015/11/09", 36, "TY"],
                    ["2015/11/10", 37, "TY"],
                    ["2015/11/11", 22, "TY"],
                    ["2015/11/12", 24, "TY"],
                    ["2015/11/13", 26, "TY"],
                    ["2015/11/14", 34, "TY"],
                    ["2015/11/15", 21, "TY"],
                    ["2015/11/16", 18, "TY"],
                    ["2015/11/17", 45, "TY"],
                    ["2015/11/18", 32, "TY"],
                    ["2015/11/19", 35, "TY"],
                    ["2015/11/20", 30, "TY"],
                    ["2015/11/21", 28, "TY"],
                    ["2015/11/22", 27, "TY"],
                    ["2015/11/23", 26, "TY"],
                    ["2015/11/24", 15, "TY"],
                    ["2015/11/25", 30, "TY"],
                    ["2015/11/26", 35, "TY"],
                    ["2015/11/27", 42, "TY"],
                    ["2015/11/28", 42, "TY"],
                    ["2015/11/08", 21, "SS"],
                    ["2015/11/09", 25, "SS"],
                    ["2015/11/10", 27, "SS"],
                    ["2015/11/11", 23, "SS"],
                    ["2015/11/12", 24, "SS"],
                    ["2015/11/13", 21, "SS"],
                    ["2015/11/14", 35, "SS"],
                    ["2015/11/15", 39, "SS"],
                    ["2015/11/16", 40, "SS"],
                    ["2015/11/17", 36, "SS"],
                    ["2015/11/18", 33, "SS"],
                    ["2015/11/19", 43, "SS"],
                    ["2015/11/20", 40, "SS"],
                    ["2015/11/21", 34, "SS"],
                    ["2015/11/22", 28, "SS"],
                    ["2015/11/23", 26, "SS"],
                    ["2015/11/24", 37, "SS"],
                    ["2015/11/25", 41, "SS"],
                    ["2015/11/26", 46, "SS"],
                    ["2015/11/27", 47, "SS"],
                    ["2015/11/28", 41, "SS"],
                    ["2015/11/08", 10, "QG"],
                    ["2015/11/09", 15, "QG"],
                    ["2015/11/10", 35, "QG"],
                    ["2015/11/11", 38, "QG"],
                    ["2015/11/12", 22, "QG"],
                    ["2015/11/13", 16, "QG"],
                    ["2015/11/14", 7, "QG"],
                    ["2015/11/15", 2, "QG"],
                    ["2015/11/16", 17, "QG"],
                    ["2015/11/17", 33, "QG"],
                    ["2015/11/18", 40, "QG"],
                    ["2015/11/19", 32, "QG"],
                    ["2015/11/20", 26, "QG"],
                    ["2015/11/21", 35, "QG"],
                    ["2015/11/22", 40, "QG"],
                    ["2015/11/23", 32, "QG"],
                    ["2015/11/24", 26, "QG"],
                    ["2015/11/25", 22, "QG"],
                    ["2015/11/26", 16, "QG"],
                    ["2015/11/27", 22, "QG"],
                    ["2015/11/28", 10, "QG"],
                    ["2015/11/08", 10, "SY"],
                    ["2015/11/09", 15, "SY"],
                    ["2015/11/10", 35, "SY"],
                    ["2015/11/11", 38, "SY"],
                    ["2015/11/12", 22, "SY"],
                    ["2015/11/13", 16, "SY"],
                    ["2015/11/14", 7, "SY"],
                    ["2015/11/15", 2, "SY"],
                    ["2015/11/16", 17, "SY"],
                    ["2015/11/17", 33, "SY"],
                    ["2015/11/18", 40, "SY"],
                    ["2015/11/19", 32, "SY"],
                    ["2015/11/20", 26, "SY"],
                    ["2015/11/21", 35, "SY"],
                    ["2015/11/22", 4, "SY"],
                    ["2015/11/23", 32, "SY"],
                    ["2015/11/24", 26, "SY"],
                    ["2015/11/25", 22, "SY"],
                    ["2015/11/26", 16, "SY"],
                    ["2015/11/27", 22, "SY"],
                    ["2015/11/28", 10, "SY"],
                    ["2015/11/08", 10, "DD"],
                    ["2015/11/09", 15, "DD"],
                    ["2015/11/10", 35, "DD"],
                    ["2015/11/11", 38, "DD"],
                    ["2015/11/12", 22, "DD"],
                    ["2015/11/13", 16, "DD"],
                    ["2015/11/14", 7, "DD"],
                    ["2015/11/15", 2, "DD"],
                    ["2015/11/16", 17, "DD"],
                    ["2015/11/17", 33, "DD"],
                    ["2015/11/18", 4, "DD"],
                    ["2015/11/19", 32, "DD"],
                    ["2015/11/20", 26, "DD"],
                    ["2015/11/21", 35, "DD"],
                    ["2015/11/22", 40, "DD"],
                    ["2015/11/23", 32, "DD"],
                    ["2015/11/24", 26, "DD"],
                    ["2015/11/25", 22, "DD"],
                    ["2015/11/26", 16, "DD"],
                    ["2015/11/27", 22, "DD"],
                    ["2015/11/28", 10, "DD"],
                ],
            }
        ],
    }

    st_echarts(option, height="500px", key="echarts")
# Create callbacks/filter data on selection
periods_filter = periods
values_region_1 = df['AveragePurchasePrice_1'][df['Regions'] == region_1].tolist()
values_region_2 = df['AveragePurchasePrice_1'][df['Regions'] == region_2].tolist()


# Create line chart with theme
st.title(region_1 + " and " + region_2)

# Open theme
with open('theme.json') as file:
    theme = json.load(file)

options = {
    "xAxis": {
        "type": "category",
        "data": periods_filter,
        "name": "Year",
    },
    "yAxis": {"type": "value", "name": "House Prices in EUR"},
    "series": [
        {"data": values_region_1, "type": "line", "name": region_1, "areaStyle": {}},
        {"data": values_region_2, "type": "line", "name": region_2, "areaStyle": {}}
    ],
    "legend": {"display": "true"}
}

st_echarts(options=options, height="400px", theme=theme,)

st.write("Source: [CBS Open data StatLine 'Existing own homes; prices, region 1995-2020'](https://opendata.cbs.nl/statline/portal.html?_la=en&_catalog=CBS&tableId=83625ENG&_theme=1102)")
示例#29
0
def render_stacked_area():
    with st.echo("below"):
        options = {
            "title": {"text": "堆叠区域图"},
            "tooltip": {
                "trigger": "axis",
                "axisPointer": {
                    "type": "cross",
                    "label": {"backgroundColor": "#6a7985"},
                },
            },
            "legend": {"data": ["邮件营销", "联盟广告", "视频广告", "直接访问", "搜索引擎"]},
            "toolbox": {"feature": {"saveAsImage": {}}},
            "grid": {"left": "3%", "right": "4%", "bottom": "3%", "containLabel": True},
            "xAxis": [
                {
                    "type": "category",
                    "boundaryGap": False,
                    "data": ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
                }
            ],
            "yAxis": [{"type": "value"}],
            "series": [
                {
                    "name": "邮件营销",
                    "type": "line",
                    "stack": "总量",
                    "areaStyle": {},
                    "data": [120, 132, 101, 134, 90, 230, 210],
                },
                {
                    "name": "联盟广告",
                    "type": "line",
                    "stack": "总量",
                    "areaStyle": {},
                    "data": [220, 182, 191, 234, 290, 330, 310],
                },
                {
                    "name": "视频广告",
                    "type": "line",
                    "stack": "总量",
                    "areaStyle": {},
                    "data": [150, 232, 201, 154, 190, 330, 410],
                },
                {
                    "name": "直接访问",
                    "type": "line",
                    "stack": "总量",
                    "areaStyle": {},
                    "data": [320, 332, 301, 334, 390, 330, 320],
                },
                {
                    "name": "搜索引擎",
                    "type": "line",
                    "stack": "总量",
                    "label": {"normal": {"show": True, "position": "top"}},
                    "areaStyle": {},
                    "data": [820, 932, 901, 934, 1290, 1330, 1320],
                },
            ],
        }
        st_echarts(options)
示例#30
0
            },
            "data": [
                {"value": code_count_Origin[0], "name": Code01},
                {"value": code_count_Origin[1], "name": Code02},
                {"value": code_count_Origin[2], "name": Code03},
                {"value": code_count_Origin[3], "name": Code04},
            ]
        }
    ]
};

c1, c2 = c.beta_columns(2)

with c1:
    st.markdown('## **▼ Chart Overview **')   
    st_echarts(options=pie_options)

    
with c2:
    st.markdown('## **▼ Pivot Overview **')

    st.write("")
    st.write("")
    st.table(dfPivotFiltered)


c3, c4 = c.beta_columns(2)

with c3:

    with st.beta_expander("🛠️ Code for chart", expanded=False):