File size: 739 Bytes
342e4c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import streamlit as st
import plotly.express as px


def plot_for_option(df, option: str, column: str):
    
    series = df[column]
    
    if option == "直方图":
        fig = px.histogram(df, x=column, title=f"{column} 的直方图")
    elif option == "饼图":
        counts = series.value_counts().reset_index()
        counts.columns = [column, 'count']
        fig = px.pie(counts, names=column, values='count', title=f"{column} 的饼图")
    elif option == "折线图":
        fig = px.line(df, y=column, title=f"{column} 的折线图")
    elif option == "箱线图":
        fig = px.box(df, y=column, title=f"{column} 的箱线图")
    else:
        st.error("未知的图表类型")
        return
    
    return fig