2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

plotly でグラフに設定できる各種タイトル

Posted at

plotlyはグラフ内に様々なタイトルを設定できる。
newplot(18).png

fig = make_subplots(
    rows=2, cols=1,
    subplot_titles=['subplot_titles_aa','subplot_titles_bb'],
    column_titles=['col_titles_1'],
    row_titles=['row_titles_1','row_titles_2'],
    x_title='x_title',
    y_title='y_title',
    specs=[[{}],[dict(secondary_y=True)]]
)
fig.update_layout(
    height=800, width=800, margin_l=120,
    title='title',
    legend_title='legend'
)

L1 = go.Scatter(x=[1,2,3], y=[1,3,1], name='foo')
L2 = go.Scatter(x=[1,2,3], y=[2,2,2], name='bar')
L3 = go.Scatter(x=[1,2,3], y=[4,80,4], name='bar2')
fig.add_traces([L1,L2,L3], rows=[1,2,2], cols=[1,1,1],secondary_ys=[False,False,True])

fig.update_layout(
    yaxis_title  = 'yaxis_title',
    yaxis2_title = 'yaxis2_title',
    yaxis3_title = 'yaxis3_title',
    xaxis_title  = 'xaxis_title',
    xaxis2_title = 'xaxis2_title',

)

fig.update_annotations(selector=dict(text='x_title'),bordercolor ='red',yshift=-50)
fig.update_annotations(selector=dict(text='y_title'),bordercolor ='blue',xshift=-80)
fig.update_annotations(selector=dict(text='col_titles_1'),bordercolor ='orange',xref='x')
fig.update_annotations(selector=dict(text='row_titles_1'),bordercolor ='yellow')
fig.update_annotations(selector=dict(text='row_titles_2'),bordercolor ='green',xshift=60)

fig.show()

デフォルトでは表示が重なってしまうタイトルもあるため、グラフの中身を考えて使用したほうが良い。(サブプロットタイトルと行・列タイトルは同時に使用しないなど)

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?