Pythonで学ぶPlotlyによるデータ可視化入門
Alex Scriven
Data Scientist
$$

add_trace() を使用$$
$$
add_trace() を使用
$$
$$
$$

from plotly.graph_objects import Figure layered_fig = Figure()bar_fig = px.bar(df, x='Date' , y='Quarterly Growth (%)')line_fig = px.line(df, x='Date' , y='Rolling YTD Growth (%)' , color_discrete_sequence=['red'])layered_fig = Figure(data= [*bar_fig.data, *line_fig.data]) layered_fig.show()

# 同じ bar_fig, line_fig を作成 line_fig2 = px.line(df, x='Date' , y='OECD Average GDP Growth (%)' , color_discrete_sequence=['green'])layered_fig = Figure(data= [*bar_fig.data , *line_fig.data, *line_fig2.data]) layered_fig.show()

# 2 つの図で作成 layered_fig = Figure(data=[*bar_fig.data, *line_fig.data])# 最後の線を追加 layered_fig.add_trace(line_fig2.data[0])
Pythonで学ぶPlotlyによるデータ可視化入門