如何调整subplot图的xlabel和ylabel到图的距离?当前的 xlabel 和 ylabel 距离图有点远。
from plotly.subplots import make_subplots
import plotly.graph_objects as go
def save_fig(fig,pngname):
width = 800
height = 400
fig.write_image(pngname,format="png", width=width, height=height, scale=1)
print("[[%s]]"%pngname)
#fig.show()
return
def plot():
fig = make_subplots(
rows=2, cols=1,
shared_xaxes=True,
vertical_spacing = 0.02,
x_title='x',
y_title='y',
specs=[[{"type": "xy"}],
[{"type": "xy"}]],
)
fig.add_trace(go.Bar(y=[2, 3, 1]),
row=1, col=1)
fig.add_trace(go.Scatter(x=[1,2,4],y=[3,2,5]),
row=2, col=1)
fontsize=10
xpading=.05
fig.update_layout(
margin=dict(l=50,t=40,r=10,b=40),
plot_bgcolor='#ffffff',#'rgb(12,163,135)',
paper_bgcolor='#ffffff',
title_x=0.5,
showlegend=True,
legend=dict(x=.02,y=1.05),
barmode='group',
bargap=0.05,
bargroupgap=0.0,
font=dict(
family="Courier New, monospace",
size=fontsize,
color="black"
),
xaxis=dict(
visible=True,
title_standoff=1,
tickangle=-15,
showline=True,
linecolor='black',
color='black',
linewidth=.5,
ticks='outside',
showgrid=True,
gridcolor='grey',
gridwidth=.5,
griddash='solid',#'dot',
),
yaxis=dict(
title_standoff=1,
showline=True,
linecolor='black',
color='black',
linewidth=.5,
showgrid=True,
gridcolor='grey',
gridwidth=.5,
griddash='solid',#'dot',
zeroline=True,
zerolinecolor='grey',
zerolinewidth=.5,
showticklabels=True,
),
xaxis2=dict(
title_standoff=1,
tickangle=-15,
showline=True,
linecolor='black',
color='black',
linewidth=.5,
ticks='outside',
showgrid=True,
gridcolor='grey',
gridwidth=.5,
griddash='solid',#'dot',
),
yaxis2=dict(
title_standoff=1,
showline=True,
linecolor='black',
color='black',
linewidth=.5,
showgrid=True,
gridcolor='grey',
gridwidth=.5,
griddash='solid',#'dot',
zeroline=True,
zerolinecolor='grey',
zerolinewidth=.5,
showticklabels=True,
),
)
save_fig(fig,"./demo.png")
return
plot()