krishaamer commited on
Commit
408537b
·
1 Parent(s): 7963821

Add Chinese titles to graphs

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. mingliu.ttf +3 -0
  3. page_likert.py +13 -7
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.ttf filter=lfs diff=lfs merge=lfs -text
mingliu.ttf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00b16e0dc854c9d045aecc71aab9b0f76b07cad58cccb3e092ef3ef1da2dc997
3
+ size 6272080
page_likert.py CHANGED
@@ -3,10 +3,14 @@ import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
  from datasets import load_dataset
 
6
 
7
  @st.cache_data
8
  def show():
9
 
 
 
 
10
  # Get Data
11
  dataset = load_dataset("krishaamer/taiwanese-college-students", data_files={'train': 'clean.csv'})
12
 
@@ -143,11 +147,11 @@ def show():
143
  # Loop through each category in likert_fields to create visualizations
144
  for category, fields in likert_fields.items():
145
  st.subheader(f'Distribution of Responses for {translation_mapping[category]}')
146
-
147
  # Calculate the number of rows needed for this category
148
  num_fields = len(fields)
149
- num_rows = -(-num_fields // 2) # This is equivalent to ceil(num_fields / 2)
150
-
151
  # Create subplots with 2 columns for this category
152
  fig, axs = plt.subplots(num_rows, 2, figsize=(15, 5 * num_rows))
153
  axs = axs.flatten() # Flatten the array of subplots
@@ -156,9 +160,12 @@ def show():
156
  for i, field in enumerate(fields):
157
  # Create the bar plot
158
  sns.countplot(x=f"{field} ({field_translation_mapping[category][i]})", data=df_translated, ax=axs[i])
159
-
160
  # Add title and labels
161
- axs[i].set_title(field_translation_mapping[category][i])
 
 
 
162
  axs[i].set_xlabel('Likert Scale')
163
  axs[i].set_ylabel('Frequency')
164
 
@@ -167,5 +174,4 @@ def show():
167
  fig.delaxes(axs[i])
168
 
169
  # Show the plot in Streamlit
170
- st.pyplot(fig)
171
-
 
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
  from datasets import load_dataset
6
+ from matplotlib.font_manager import FontProperties
7
 
8
  @st.cache_data
9
  def show():
10
 
11
+ # Chinese font
12
+ chinese_font = FontProperties(fname='mingliu.ttf')
13
+
14
  # Get Data
15
  dataset = load_dataset("krishaamer/taiwanese-college-students", data_files={'train': 'clean.csv'})
16
 
 
147
  # Loop through each category in likert_fields to create visualizations
148
  for category, fields in likert_fields.items():
149
  st.subheader(f'Distribution of Responses for {translation_mapping[category]}')
150
+
151
  # Calculate the number of rows needed for this category
152
  num_fields = len(fields)
153
+ num_rows = -(-num_fields // 2) # Equivalent to ceil(num_fields / 2)
154
+
155
  # Create subplots with 2 columns for this category
156
  fig, axs = plt.subplots(num_rows, 2, figsize=(15, 5 * num_rows))
157
  axs = axs.flatten() # Flatten the array of subplots
 
160
  for i, field in enumerate(fields):
161
  # Create the bar plot
162
  sns.countplot(x=f"{field} ({field_translation_mapping[category][i]})", data=df_translated, ax=axs[i])
163
+
164
  # Add title and labels
165
+ title_chinese = field
166
+ title_english = field_translation_mapping[category][i]
167
+ axs[i].set_title(f"{title_chinese}\n{title_english}", fontproperties=chinese_font) # Add both versions to the title
168
+
169
  axs[i].set_xlabel('Likert Scale')
170
  axs[i].set_ylabel('Frequency')
171
 
 
174
  fig.delaxes(axs[i])
175
 
176
  # Show the plot in Streamlit
177
+ st.pyplot(fig)