Spaces:
Sleeping
Sleeping
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 | |
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) |