从Plotly 4.0.0开始,您可以将主轴标题分别添加为x_title和y_title:
from plotly.subplots import make_subplots
fig = make_subplots(rows=2,cols=2,x_title='Your master x-title',y_title='Your master y-title',subplot_titles=('Subplot title1','Subplot title2','Subplot title3','Subplot title4'))
,
此代码中的问题是xaxis和yaxis没有任何标签。
您可以通过设置图形的结构来编辑任何轴:
fig['layout']['xaxis']['title']='Label x-axis 1'
除此之外,当前代码仅对所有情节应用一个标题
根据用户shaik moeed提到的绘图版本,您可以在图形定义中包括subplot_titles
:
fig = make_subplots(rows=1,'Subplot title2'))
情节:
代码:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# plotly fig setup
fig = make_subplots(rows=1,'Subplot title2'))
# traces
fig.add_trace(
go.Scatter(x=[1,2,3],y=[4,5,6]),row=1,col=1
)
fig.add_trace(
go.Scatter(x=[20,30,40],y=[50,60,70]),col=2
)
# edit axis labels
fig['layout']['xaxis']['title']='Label x-axis 1'
fig['layout']['xaxis2']['title']='Label x-axis 2'
fig['layout']['yaxis']['title']='Label y-axis 1'
fig['layout']['yaxis2']['title']='Label y-axis 2'
# plot it
fig.show()
,
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# plotly fig setup
fig = make_subplots(rows=1,vertical_spacing=0.09,col=2
)
#fig.add_trace(go.Scatter(x=time_list,y=C_hl0),# row=1,col=1)
fig.update_layout(height=1600,width=1000,title_text="Whatever you want")
for i in range(1,5):
fig['layout']['xaxis{}'.format(i)]['title']='Label X axis 1'
fig['layout']['yaxis{}'.format(i)]['title']='Label X axis 2'
fig.show()
#If you want to save your plot into your local directory
import plotly.io as pio
pio.kaleido.scope.default_format = "png"
fig.write_image(r"C:\fig1.png")
本文链接:https://www.f2er.com/3105164.html