Skip to content

Commit 2e30f28

Browse files
authored
Added x and y axis titles to add_trace function
1 parent 94790d2 commit 2e30f28

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

plotly/basedatatypes.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,14 @@ def _validate_rows_cols(name, n, vals):
20062006
BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals)
20072007

20082008
def add_trace(
2009-
self, trace, row=None, col=None, secondary_y=None, exclude_empty_subplots=False
2009+
self,
2010+
trace,
2011+
row=None,
2012+
col=None,
2013+
secondary_y=None,
2014+
exclude_empty_subplots=False,
2015+
xaxis_title=None,
2016+
yaxis_title=None,
20102017
):
20112018
"""
20122019
Add a trace to the figure
@@ -2050,6 +2057,12 @@ def add_trace(
20502057
exclude_empty_subplots: boolean
20512058
If True, the trace will not be added to subplots that don't already
20522059
have traces.
2060+
x_axis_title: str or None (default None)
2061+
The title of the x-axis for the subplot at the specified row and
2062+
col.
2063+
y_axis_title: str or None (default None)
2064+
The title of the y-axis for the subplot at the specified row and
2065+
col.
20532066
Returns
20542067
-------
20552068
BaseFigure
@@ -2101,17 +2114,27 @@ def add_trace(
21012114
col=c,
21022115
secondary_y=secondary_y,
21032116
exclude_empty_subplots=exclude_empty_subplots,
2117+
xaxis_title=xaxis_title,
2118+
yaxis_title=yaxis_title,
21042119
)
21052120
return self
2106-
2107-
return self.add_traces(
2121+
2122+
result = self.add_traces(
21082123
data=[trace],
21092124
rows=[row] if row is not None else None,
21102125
cols=[col] if col is not None else None,
21112126
secondary_ys=[secondary_y] if secondary_y is not None else None,
21122127
exclude_empty_subplots=exclude_empty_subplots,
21132128
)
21142129

2130+
if row is not None and col is not None:
2131+
if xaxis_title is not None:
2132+
self.update_xaxes(title_text=xaxis_title, row=row, col=col)
2133+
if yaxis_title is not None:
2134+
self.update_yaxes(title_text=yaxis_title, row=row, col=col)
2135+
2136+
return result
2137+
21152138
def add_traces(
21162139
self,
21172140
data,

0 commit comments

Comments
 (0)