前提・実現したいこと
各motion3個の線を表示させつつ(計10個の線)、凡例ラベルの同名で表示されているものを1つにまとめたい
発生している問題・エラーメッセージ
こちらの画像の凡例ラベルの[motion0],[motion2],[motion4]を一つだけ表示させたいのですが、以下の様に表示されてしまいます。同色の線を描画しつつ、同名のmotionを1つのみ表示させるには、どの箇所に変更点を加えれば良いかわからず、質問させていただきました。どうか、ご教示よろしくお願い致します。
該当のソースコード
長く見づらくて申し訳ありませんが、ご覧いただけると幸いです。よろしくお願い致します。
#plot_Duplication.py import pandas as pd import matplotlib.pyplot as plt import os #####RuntimeWarning エラー回避 import numpy as np np.seterr(divide='ignore', invalid='ignore') ##### #出力処理 def Output(): motions = ["0","2","4"] speedes02 = ["0","1","2"] speedes4 = ["1","2","3","4"] TF = ["Time","Freq"] tp_list = ["pickup","torque"] Time_features = ["std","cf"] Freq_features = ["Rotation2_section2"] Date = input("日付入力:") mkdir = "//../Date" read_path = "//../filedata" os.chdir(read_path) for sample in samples: for tf in TF: for tp in tp_list: if tf in "Time": for feature in Time_features: plt.figure(figsize=(Xsize,Ysize)) plt.grid() title_name = "Duplicated_"+feature for motion in motions: if motion in "4": for speed in speedes4: df = pd.read_csv("Timedata.csv") df = df.query("motion_type in ["+motion+"] & speed_setting in ["+speed+"]") Time_feature_plot(df,feature,tf,tp,title_name,motion,speed) save=tp+"_"+sample+"_"+feature+"_duplicated.png" else: for speed in speedes02: df = pd.read_csv("Timedata.csv") df = df.query("motion_type in ["+motion+"] & speed_setting in ["+speed+"]") Time_feature_plot(df,feature,tf,tp,title_name,motion,speed) save=tp+"_"+sample+"_"+feature+"_duplicated.png" graph_label(title_name,feature) plt.savefig(mkdir+"/"+save) elif tf in "Freq": for feature in Freq_features: plt.figure(figsize=(Xsize,Ysize)) plt.grid() title_name = "Duplicated_"+feature for motion in motions: if motion in "4": for speed in speedes4: df = pd.read_csv("Freqdata.csv") df = df.query("motion_type in ["+motion+"] & speed_setting in ["+speed+"]") Freq_feature_plot(df,feature,tf,tp,title_name,motion,speed) save=tp+"_"+sample+"_"+feature+"_duplicated.png" else: for speed in speedes02: df = pd.read_csv("Freqdata.csv") df = df.query("motion_type in ["+motion+"] & speed_setting in ["+speed+"]") Freq_feature_plot(df,feature,tf,tp,title_name,motion,speed) save=tp+"_"+sample+"_"+feature+"_duplicated.png" graph_label(title_name,feature) plt.savefig(mkdir+"/"+save) #Timefeature def Time_feature_plot(df,feature,tf,tp,title_name,motion,speed): ot = df["operating_time"] fp = df[feature+"_section2_"+tp] if motion in "0": plt.plot(ot,fp,linestyle="solid",label=motion+"motion",color="red") if motion in "2": plt.plot(ot,fp,linestyle="solid",label=motion+"motion",color="blue") if motion in "4": plt.plot(ot,fp,linestyle="solid",label=motion+"motion",color="green") #Freqfeature def Freq_feature_plot(df,feature,tf,tp,title_name,motion,speed): ot = df["operating_time"] fp = df[feature] if motion in "0": plt.plot(ot,fp,linestyle="solid",label="motion"+motion,color="red") if motion in "2": plt.plot(ot,fp,linestyle="solid",label="motion"+motion,color="blue") if motion in "4": plt.plot(ot,fp,linestyle="solid",label="motion"+motion,color="green") if __name__ == "__main__": #グラフサイズ手動設定 """ Xsize = int(input("グラフサイズX軸...")) Ysize = int(input("グラフサイズY軸...")) plt.rcParams["font.size"] = int(input("ラベルサイズ...")) """ #グラフサイズ自動設定 Xsize = 10 Ysize = 10 plt.rcParams["font.size"] = 16 plt.rcParams["xtick.labelsize"] plt.rcParams["ytick.labelsize"] HDnumber = [] samples = [] #読み込むcsvファイル some_csv = int(input("読み込み数...")) for csv_cnt in range(some_csv): HDnumber = input("読み込みデータ番号:") samples.append(HDnumber) Output()

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/22 08:09