Center subplots in a larger width figure

Hey @GeminyCriquet ,

Welcome to the forum.

This is trial and error. I simply added another column and tinkered column widths.

import numpy as np
from plotly.subplots import make_subplots
from plotly.graph_objs import Contour, Scatter
import plotly.graph_objects as go

figure = make_subplots(rows=1, cols=3, shared_yaxes=True, column_widths=[0.4, 0.8, 1.2], horizontal_spacing=0.01)

t = np.linspace(0, 2*np.pi, 100)

trace_1 = Scatter(x = np.cos(t),
                  y = t,
                  mode = 'lines')

trace_2 = Contour(z=[[10, 12.5, 20],
                         [5.625, 8.125, 15.625],
                         [2.5, 5., 12.5],
                         [0.625, 3.125, 10.625],
                         [0, 2.5, 10]],
                  x=[-9, -7 , -5], # horizontal axis
                  y=[0, 1, 4, 5, 7], # vertical axis
                  contours_coloring = 'heatmap',
                  contours_showlabels = True,
                  colorbar = dict(x=0.47,  thickness=15)  # colorbar position
                  )

figure.add_trace(trace_1, row=1, col=1)
figure.add_trace(trace_2, row=1, col=2)

figure.update_layout(title_text = 'Title<br><span style="font-size:14px">Subtitle</span>',
                     xaxis1 = dict(title='x1', constrain='domain'),
                     xaxis2 = dict(title='x2', constrain='domain'),
                     yaxis = dict(title='y', constrain='domain', scaleanchor="x2", scaleratio=1))



figure.show(width=1080, height=720)

Have a nice day.

1 Like