Skip to content
  • Sponsor plotly/plotly.py

  • Notifications You must be signed in to change notification settings
  • Fork 2.7k

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 4 commits into
base: main
Choose a base branch
from
Open
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
@@ -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
29 changes: 26 additions & 3 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
@@ -2028,7 +2028,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
@@ -2072,6 +2079,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
@@ -2123,17 +2136,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,