From 2e30f28b13371fc8065889c29c766ca200b6198b Mon Sep 17 00:00:00 2001 From: Mia Patrikios <118705616+mpatrikios@users.noreply.github.com> Date: Sat, 12 Apr 2025 19:23:30 -0400 Subject: [PATCH 1/2] Added x and y axis titles to add_trace function --- plotly/basedatatypes.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/plotly/basedatatypes.py b/plotly/basedatatypes.py index a3044f6763a..c6fd7156e46 100644 --- a/plotly/basedatatypes.py +++ b/plotly/basedatatypes.py @@ -2006,7 +2006,14 @@ def _validate_rows_cols(name, n, vals): BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals) def add_trace( - self, trace, row=None, col=None, secondary_y=None, exclude_empty_subplots=False + self, + trace, + row=None, + col=None, + secondary_y=None, + exclude_empty_subplots=False, + xaxis_title=None, + yaxis_title=None, ): """ Add a trace to the figure @@ -2050,6 +2057,12 @@ def add_trace( exclude_empty_subplots: boolean If True, the trace will not be added to subplots that don't already have traces. + x_axis_title: str or None (default None) + The title of the x-axis for the subplot at the specified row and + col. + y_axis_title: str or None (default None) + The title of the y-axis for the subplot at the specified row and + col. Returns ------- BaseFigure @@ -2101,10 +2114,12 @@ def add_trace( col=c, secondary_y=secondary_y, exclude_empty_subplots=exclude_empty_subplots, + xaxis_title=xaxis_title, + yaxis_title=yaxis_title, ) return self - - return self.add_traces( + + result = self.add_traces( data=[trace], rows=[row] if row is not None else None, cols=[col] if col is not None else None, @@ -2112,6 +2127,14 @@ def add_trace( exclude_empty_subplots=exclude_empty_subplots, ) + if row is not None and col is not None: + if xaxis_title is not None: + self.update_xaxes(title_text=xaxis_title, row=row, col=col) + if yaxis_title is not None: + self.update_yaxes(title_text=yaxis_title, row=row, col=col) + + return result + def add_traces( self, data, From 02ccd1dbeb22163a6c5c50f55d3579401c246421 Mon Sep 17 00:00:00 2001 From: Mia Patrikios <118705616+mpatrikios@users.noreply.github.com> Date: Sat, 12 Apr 2025 19:48:05 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89da1e55f17..e7b4841da09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix third-party widget display issues in v6 [[#5102]https://github.com/plotly/plotly.py/pull/5102] +### Added +- Added `xaxis_title` and `yaxis_title` parameters to `add_trace()` method for more concise subplot creation + ## [6.0.1] - 2025-03-14 ### Updated