krishaamer commited on
Commit
24b6da8
·
1 Parent(s): 434cd9c

Stub for more charts

Browse files
fields/boolean_fields.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ boolean_fields = [
2
+ '你/妳有沒有抵制過某公司?',
3
+ '你/妳覺得目前有任何投資嗎?'
4
+ ]
page_investing.py CHANGED
@@ -3,12 +3,15 @@ import pandas as pd
3
  from matplotlib.font_manager import FontProperties
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
 
6
 
7
  @st.cache_data
8
  def show(df):
9
  # Load the Chinese font
10
- chinese_font = FontProperties(fname='mingliu.ttf', size=12)
11
  st.title("Investing")
 
 
12
  show_investment_count(df, font_prop=chinese_font)
13
 
14
 
 
3
  from matplotlib.font_manager import FontProperties
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
+ from fields.likert_fields import likert_fields
7
 
8
  @st.cache_data
9
  def show(df):
10
  # Load the Chinese font
11
+ chinese_font = FontProperties(fname='notosans.ttf', size=12)
12
  st.title("Investing")
13
+ st.markdown(
14
+ f"<h2 style='text-align: center;'>Investing Experience (Overall)</h2>", unsafe_allow_html=True)
15
  show_investment_count(df, font_prop=chinese_font)
16
 
17
 
page_shopping.py CHANGED
@@ -4,15 +4,18 @@ import matplotlib.pyplot as plt
4
  import seaborn as sns
5
  import pandas as pd
6
  import numpy as np
 
 
7
 
8
- @st.cache_data
9
  def show(df):
10
  # Load the Chinese font
11
- chinese_font = FontProperties(fname='mingliu.ttf', size=12)
12
  st.title("Shopping")
13
  st.markdown(
14
- f"<h2 style='text-align: center;'>Boycott Count</h2>", unsafe_allow_html=True)
15
  show_boycott_count(df, font_prop=chinese_font)
 
16
 
17
  def show_boycott_count(df, font_prop):
18
  # Count the number of people who have invested and who have not
@@ -35,4 +38,44 @@ def show_boycott_count(df, font_prop):
35
  plt.text(index, value, str(value), ha='center', va='bottom', fontproperties=font_prop)
36
 
37
  # Display the chart in Streamlit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  st.pyplot(plt)
 
4
  import seaborn as sns
5
  import pandas as pd
6
  import numpy as np
7
+ from fields.likert_flat_fields import likert_flat_fields
8
+ #from fields.boolean_fields import boolean_fields
9
 
10
+ #@st.cache_data
11
  def show(df):
12
  # Load the Chinese font
13
+ chinese_font = FontProperties(fname='notosans.ttf', size=12)
14
  st.title("Shopping")
15
  st.markdown(
16
+ f"<h2 style='text-align: center;'>Boycott Count (Overall)</h2>", unsafe_allow_html=True)
17
  show_boycott_count(df, font_prop=chinese_font)
18
+ #generate_correlation_chart(df, chinese_font)
19
 
20
  def show_boycott_count(df, font_prop):
21
  # Count the number of people who have invested and who have not
 
38
  plt.text(index, value, str(value), ha='center', va='bottom', fontproperties=font_prop)
39
 
40
  # Display the chart in Streamlit
41
+ st.pyplot(plt)
42
+
43
+
44
+ def generate_correlation_chart(df, chinese_font):
45
+
46
+ boolean_fields = [
47
+ '你/妳覺得目前有任何投資嗎?'
48
+ ]
49
+
50
+ # Encode boolean fields
51
+ for field in boolean_fields:
52
+ df[field + '_encoded'] = df[field].map({'有': 1, '沒有': 0})
53
+
54
+ # Combine all fields for correlation
55
+ all_fields = likert_flat_fields + [f"{field}_encoded" for field in boolean_fields]
56
+
57
+ # Calculate the correlation matrix
58
+ correlation_data = df[all_fields].corr()
59
+
60
+ # Define a threshold for strong correlations
61
+ threshold = 0.5
62
+
63
+ # Find all fields that have at least one strong correlation
64
+ strong_fields = correlation_data.columns[np.abs(correlation_data).max() > threshold]
65
+
66
+ # Filter the correlation matrix to only include these fields
67
+ filtered_correlation_data = correlation_data.loc[strong_fields, strong_fields]
68
+
69
+ # Plot the correlation matrix
70
+ plt.figure(figsize=(10, 8))
71
+ ax = sns.heatmap(filtered_correlation_data, annot=True, fmt=".2f", cmap="coolwarm")
72
+
73
+ # Set the labels with the Chinese font
74
+ ax.set_xticklabels(ax.get_xticklabels(), fontproperties=chinese_font, rotation=45, ha='right')
75
+ ax.set_yticklabels(ax.get_yticklabels(), fontproperties=chinese_font, rotation=0)
76
+
77
+ # Set the title with the Chinese font
78
+ plt.title("強相關分析", fontproperties=chinese_font)
79
+
80
+ # Show the plot in Streamlit
81
  st.pyplot(plt)