From 3849f9686c357f80e3b340595a4d3f695ab7a1d6 Mon Sep 17 00:00:00 2001 From: haturatu Date: Sat, 15 Jun 2024 15:09:14 +0900 Subject: add japanese fonts support, add map key change --- hikakucsv.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'hikakucsv.py') 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ファイルをアップロードしてください。") -- cgit v1.2.3