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 | |
def show(df): | |
# Load the Chinese font | |
chinese_font = FontProperties(fname='mingliu.ttf', size=12) | |
st.title("Investing") | |
show_investment_count(df, font_prop=chinese_font) | |
def show_investment_count(df, font_prop): | |
# Count the number of people who have invested and who have not | |
investment_count = df["你/妳覺得目前有任何投資嗎?"].value_counts().reset_index() | |
investment_count.columns = ['Investment', 'Count'] | |
# Create a bar chart using seaborn | |
plt.figure(figsize=(10, 6)) | |
barplot = sns.barplot(x='Investment', y='Count', data=investment_count, palette='viridis') | |
ax = plt.gca() # Get the current Axes instance on the current figure matching the given keyword args, or create one. | |
ax.set_xticklabels(ax.get_xticklabels(), fontproperties=font_prop) | |
# Add labels and title | |
plt.xlabel('Do you currently have any investment?', fontsize=12, fontproperties=font_prop) | |
plt.ylabel('Count', fontsize=12, fontproperties=font_prop) | |
plt.title("Number of People Who Have/Haven't Invested", fontsize=16, fontproperties=font_prop) | |
# Display values on the bars | |
for index, value in enumerate(investment_count['Count']): | |
plt.text(index, value, str(value), ha='center', va='bottom', fontproperties=font_prop) | |
# Display the chart in Streamlit | |
st.pyplot(plt) | |