summaryrefslogtreecommitdiff
path: root/hikakucsv.py
diff options
context:
space:
mode:
authorhaturatu <warsaw21g@gmail.com>2024-06-15 15:09:14 +0900
committerhaturatu <warsaw21g@gmail.com>2024-06-15 15:09:14 +0900
commit3849f9686c357f80e3b340595a4d3f695ab7a1d6 (patch)
tree7bf89952e048188fc339a1af46b37bfee8462c15 /hikakucsv.py
parent448dad696147a15d475a5a52a84ef77c8ffa4078 (diff)
add japanese fonts support, add map key change
Diffstat (limited to 'hikakucsv.py')
-rwxr-xr-xhikakucsv.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/hikakucsv.py b/hikakucsv.py
index c8bd8b5..dbe54ed 100755
--- a/hikakucsv.py
+++ b/hikakucsv.py
@@ -3,6 +3,10 @@
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
+import matplotlib.font_manager as fm
+
+# 日本語フォントの設定
+plt.rcParams['font.family'] = 'Noto Sans CJK JP'
# Streamlitアプリケーションのタイトル設定
st.title('CSVファイル比較チャート')
@@ -33,20 +37,37 @@ if uploaded_files:
df[date_column] = pd.to_datetime(df[date_column])
# プロットの作成
- plt.figure(figsize=(12, 6))
+ fig, ax1 = plt.subplots(figsize=(12, 6))
+ ax2 = ax1.twinx()
- # ファイルごとにプロットしたいカラムを選択
for i, df in enumerate(file_list):
+ # ファイルごとに縦軸の位置を選択するためのセレクトボックスを作成
+ axis_position = st.selectbox(f'ファイル{i+1}の縦軸の位置を選択してください', ["左", "右"], index=0, key=f'axis_position_{i}')
+
+ # ファイルごとにプロットしたいカラムを選択
col = st.selectbox(f'ファイル{i+1}のカラムを選択してください', [col for col in df.columns if col != date_column], key=f'col_select_{i}')
- # データフレームごとにプロット
- plt.plot(df[date_column], df[col], label=f'{col} (File {i+1})')
- plt.xlabel(date_column)
- plt.ylabel('Value')
- plt.title('CSV to FRED')
- plt.legend()
+ # 凡例名を入力するためのテキストボックスを作成
+ legend_name = st.text_input(f'ファイル{i+1}の凡例名を入力してください(デフォルトはカラム名: {col})', col, key=f'legend_input_{i}')
+
+ # 縦軸の位置に応じてデータフレームをプロット
+ if axis_position == "左":
+ ax1.plot(df[date_column], df[col], label=legend_name, color=f'C{i}')
+ else:
+ ax2.plot(df[date_column], df[col], label=legend_name, color=f'C{i}', linestyle='--')
+
+ ax1.set_xlabel(date_column)
+ ax1.set_ylabel('')
+ ax2.set_ylabel('')
+
+ # 凡例の設定(左軸の凡例を右側に、右軸の凡例を左側に)
+ handles1, labels1 = ax1.get_legend_handles_labels()
+ handles2, labels2 = ax2.get_legend_handles_labels()
+ ax1.legend(handles2, labels2, loc='upper left')
+ ax2.legend(handles1, labels1, loc='upper right')
- st.pyplot(plt.gcf())
+ plt.title('CSV to plot')
+ st.pyplot(fig)
else:
st.write("CSVファイルをアップロードしてください。")