File size: 1,013 Bytes
574481e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a66365
574481e
 
 
 
7a66365
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
import plotly.graph_objects as go
import plotly.express as px

def plot_emotion_distribution(emotion_dict):
    """

    绘制情绪概率分布图(雷达图)

    

    Args:

        emotion_dict: 包含情绪标签和对应概率的字典

    """
    emotions = list(emotion_dict.keys())
    probabilities = [float(emotion_dict[emotion].strip('%')) / 100 for emotion in emotions]  # 转换为浮点数

    # 创建雷达图
    fig = go.Figure()

    fig.add_trace(go.Scatterpolar(
        r=probabilities + [probabilities[0]],  # 闭合图形
        theta=emotions + [emotions[0]],  # 闭合图形
        fill='toself',
        name='Emotion Distribution'
    ))

    fig.update_layout(
        title="Emotion Distribution",
        polar=dict(
            radialaxis=dict(
                visible=True,
                range=[0, 1]  # 设置范围
            )),
        showlegend=False
    )

    st.plotly_chart(fig, use_container_width=True)