File size: 1,365 Bytes
0a6970e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
import streamlit as st
import pandas as pd
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
import seaborn as sns
from fields.likert_fields import likert_fields

@st.cache_data
def show(df):
    # Load the Chinese font
    chinese_font = FontProperties(fname='notosans.ttf', size=12)
    st.title("Environment")

    st.markdown(
                f"<h2 style='text-align: center;'>Ranking Experiment</h2>", unsafe_allow_html=True)
    visualize_ecosystem_sensitivity(df, chinese_font)



def visualize_ecosystem_sensitivity(df, chinese_font):
  
    # Field related to ecosystem sensitivity to environmental degradation
    ecosystem_field = "你/妳覺得如何依照生態系對環境惡化的敏感度來排名?"

    # Summarize the data
    ecosystem_data = df[ecosystem_field].value_counts().head(20)  # Adjust the number as needed
    
    # Plot the data
    plt.figure(figsize=(10, 6))
    ecosystem_data.plot(kind='bar', color='forestgreen')
    plt.title('Ecosystem Sensitivity to Environmental Degradation', fontproperties=chinese_font)
    plt.xlabel('Sensitivity Ranking', fontproperties=chinese_font)
    plt.ylabel('Number of Responses', fontproperties=chinese_font)
    plt.xticks(rotation=45, ha='right', fontproperties=chinese_font)
    plt.tight_layout()

    # Display the plot in Streamlit
    st.pyplot(plt)