Skip to content

Added x and y axis titles to add_trace function #5058 #5141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2101,17 +2114,27 @@ 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,
secondary_ys=[secondary_y] if secondary_y is not None else None,
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,
Expand Down