👏
Plotlyを試す1
import plotly.express as px
import pandas as pd
# データの読み込み
df1 = pd.read_csv('data1.csv')
df2 = pd.read_csv('data2.csv')
df3 = pd.read_csv('data3.csv')
# 凡例名の設定
names = ['data1', 'data2', 'data3']
# 全ての凡例を非表示にする
visible = [False] * len(names)
# データを散布図としてプロット
fig = px.scatter(df1, x='x', y='y', color_discrete_sequence=['blue'], name=names[0], visible=visible[0])
fig.add_scatter(x=df2['x'], y=df2['y'], mode='markers', name=names[1], visible=visible[1])
fig.add_scatter(x=df3['x'], y=df3['y'], mode='markers', name=names[2], visible=visible[2])
# レイアウトの設定
fig.update_layout(
title='Multiple Scatter Plot',
xaxis_title='X Axis',
yaxis_title='Y Axis',
updatemenus=[
dict(
buttons=list([
dict(
args=[{'visible': [True, False, False]}],
label=names[0],
method='update'
),
dict(
args=[{'visible': [False, True, False]}],
label=names[1],
method='update'
),
dict(
args=[{'visible': [False, False, True]}],
label=names[2],
method='update'
),
dict(
args=[{'visible': [True] * len(names)}],
label='All',
method='update'
)
]),
direction='down',
showactive=True,
xanchor='left',
yanchor='top'
)
]
)
# グラフの表示
fig.show()
Discussion