diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 3e01f445c2..1c44041f5d 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -374,17 +374,26 @@ def configure_cartesian_marginal_axes(args, fig, orders): set_cartesian_axis_opts(args, xaxis, "x", orders) # Configure axis ticks on marginal subplots + # Don't change the marginal grid settings if the template already specifies `showgrid` + if ( + args["template"].layout.xaxis.showgrid is None + or args["template"].layout.yaxis.showgrid is None + ): + grid_set = False + else: + grid_set = True + if args["marginal_x"]: - fig.update_yaxes( - showticklabels=False, showgrid=args["marginal_x"] == "histogram", row=nrows - ) - fig.update_xaxes(showgrid=True, row=nrows) + fig.update_yaxes(showticklabels=False, showline=False, ticks="", row=nrows) + if not grid_set: + fig.update_yaxes(showgrid=args["marginal_x"] == "histogram", row=nrows) + fig.update_xaxes(showgrid=True, row=nrows) if args["marginal_y"]: - fig.update_xaxes( - showticklabels=False, showgrid=args["marginal_y"] == "histogram", col=ncols - ) - fig.update_yaxes(showgrid=True, col=ncols) + fig.update_xaxes(showticklabels=False, showline=False, ticks="", col=ncols) + if not grid_set: + fig.update_xaxes(showgrid=args["marginal_y"] == "histogram", col=ncols) + fig.update_yaxes(showgrid=True, col=ncols) # Add axis titles to non-marginal subplots y_title = get_decorated_label(args, args["y"], "y")