[英]x axes titles on subplots Plotly Python
我正在嘗試將x-axes
和y-axes
的相同標題添加到顯示為子圖的四個甘特圖。 我在網上找到了figs.update_layout()
但是,這僅顯示第一個圖表上的標題,而不是全部。 我用 R 找到了一些答案,但是對 python 的任何幫助都會很棒
figs = make_subplots(
rows=2, cols=2,
shared_xaxes=False,
subplot_titles =('Plot 1', 'PLot 2', 'PLot 3', 'Plot 4')
)
figs.update_layout(
title="Plot Title",
xaxis_title="Miliseconds",
yaxis_title="Services",
)
for trace in fig_operable.data:
figs.add_trace(trace, row=1, col=1)
for trace in fig_dynamic.data:
figs.add_trace(trace, row=2, col=1)
for trace in fig_early.data:
figs.add_trace(trace, row=1, col=2)
for trace in fig_hmi.data:
figs.add_trace(trace, row=2, col=2)
figs.update_layout(showlegend=False, title_text="Title of charts")
figs.show()
IIUC你正在尋找類似的東西
import numpy as np
import plotly.graph_objs as go
from plotly.subplots import make_subplots
subplot_titles = ['Plot 1', 'Plot 2', 'Plot 3', 'Plot 4']
xaxis_title="Miliseconds"
yaxis_title="Services"
rows = 2
cols = 2
height = 300 * rows
trace = go.Scatter(x=np.linspace(1,100,100),
y=np.linspace(1,100,100))
fig = make_subplots(rows=rows, cols=cols,
shared_xaxes=False,
subplot_titles=subplot_titles
)
for i, col in enumerate(subplot_titles):
r = int(np.ceil(((i+1)/cols)))
c = i%2+1
fig.add_trace(trace, row=r, col=c)
fig.update_xaxes(title_text=xaxis_title, row=r, col=c)
fig.update_yaxes(title_text=yaxis_title, row=r, col=c)
fig.update_layout(showlegend=False,
title_text="Title of charts",
title_x=0.5,
height=height)
fig.show()
如果您需要任何其他疑問,可以查看此處的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.