diff --git a/packages/python/chart-studio/chart_studio/plotly/plotly.py b/packages/python/chart-studio/chart_studio/plotly/plotly.py index 476b4081700..6a11d815dad 100644 --- a/packages/python/chart-studio/chart_studio/plotly/plotly.py +++ b/packages/python/chart-studio/chart_studio/plotly/plotly.py @@ -1793,7 +1793,7 @@ def _extract_grid_from_fig_like(fig, grid=None, path=''): trace_type = trace_dict.get('type', 'scatter') if trace_type not in reference_traces: reference_traces[trace_type] = reference_fig.add_trace( - {'type': trace_type}) + {'type': trace_type}).data[-1] reference_trace = reference_traces[trace_type] _extract_grid_graph_obj( diff --git a/packages/python/plotly/codegen/datatypes.py b/packages/python/plotly/codegen/datatypes.py index 5b541625605..a4bd64d0752 100644 --- a/packages/python/plotly/codegen/datatypes.py +++ b/packages/python/plotly/codegen/datatypes.py @@ -265,7 +265,13 @@ def __init__(self""") f'dict of properties compatible with this constructor ' f'or an instance of {class_name}')] - add_docstring(buffer, node, header=header, prepend_extras=extras) + add_docstring( + buffer, + node, + header=header, + prepend_extras=extras, + return_type=node.name_datatype_class, + ) buffer.write(f""" super({datatype_class}, self).__init__('{node.name_property}') @@ -424,7 +430,14 @@ def add_constructor_params(buffer, ):""") -def add_docstring(buffer, node, header, prepend_extras=(), append_extras=()): +def add_docstring( + buffer, + node, + header, + prepend_extras=(), + append_extras=(), + return_type=None, +): """ Write docstring for a compound datatype node @@ -443,6 +456,8 @@ def add_docstring(buffer, node, header, prepend_extras=(), append_extras=()): append_extras : List or tuple of propery name / description pairs that should be included at the end of the docstring + return_type : + The docstring return type Returns ------- @@ -511,7 +526,7 @@ def add_docstring(buffer, node, header, prepend_extras=(), append_extras=()): Returns ------- - {node.name_datatype_class} + {return_type} \"\"\"""") diff --git a/packages/python/plotly/codegen/figure.py b/packages/python/plotly/codegen/figure.py index 42820dad2bd..aed4804053d 100644 --- a/packages/python/plotly/codegen/figure.py +++ b/packages/python/plotly/codegen/figure.py @@ -110,26 +110,6 @@ def __init__(self, data=None, layout=None, d for d in trace_node.child_datatypes if d.name_property == 'yaxis' ]) - if include_secondary_y: - secondary_y_1 = ', secondary_y=None' - secondary_y_2 = ', secondary_y=secondary_y' - secondary_y_docstring = f""" - secondary_y: boolean or None (default None) - * If True, only select yaxis objects associated with the secondary - y-axis of the subplot. - * If False, only select yaxis objects associated with the primary - y-axis of the subplot. - * If None (the default), do not filter yaxis objects based on - a secondary y-axis condition. - - To select yaxis objects by secondary y-axis, the Figure must - have been created using plotly.subplots.make_subplots. See - the docstring for the specs argument to make_subplots for more - info on creating subplots with secondary y-axes.""" - else: - secondary_y_1 = '' - secondary_y_2 = '' - secondary_y_docstring = '' # #### Function signature #### buffer.write(f""" @@ -171,7 +151,13 @@ def add_{trace_node.plotly_name}(self""") """) ) - add_docstring(buffer, trace_node, header, append_extras=doc_extras) + add_docstring( + buffer, + trace_node, + header, + append_extras=doc_extras, + return_type=fig_classname, + ) # #### Function body #### buffer.write(f""" diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 0a09447b239..82f31c4b96f 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -1447,12 +1447,12 @@ def add_trace(self, trace, row=None, col=None, secondary_y=None): (scatter, bar, etc.) Returns ------- - BaseTraceType - The newly added trace + BaseFigure + The Figure that add_trace was called on Examples -------- - >>> from plotly import tools + >>> from plotly import subplots >>> import plotly.graph_objs as go Add two Scatter traces to a figure @@ -1462,11 +1462,7 @@ def add_trace(self, trace, row=None, col=None, secondary_y=None): Add two Scatter traces to vertically stacked subplots - >>> fig = tools.make_subplots(rows=2) - This is the format of your plot grid: - [ (1,1) x1,y1 ] - [ (2,1) x2,y2 ] - + >>> fig = subplots.make_subplots(rows=2) >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1) >>> fig.add_trace(go.Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1) """ @@ -1492,7 +1488,7 @@ def add_trace(self, trace, row=None, col=None, secondary_y=None): 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 - )[0] + ) def add_traces(self, data, rows=None, cols=None, secondary_ys=None): """ @@ -1528,12 +1524,12 @@ def add_traces(self, data, rows=None, cols=None, secondary_ys=None): Returns ------- - tuple[BaseTraceType] - Tuple of the newly added traces + BaseFigure + The Figure that add_traces was called on Examples -------- - >>> from plotly import tools + >>> from plotly import subplots >>> import plotly.graph_objs as go Add two Scatter traces to a figure @@ -1542,11 +1538,7 @@ def add_traces(self, data, rows=None, cols=None, secondary_ys=None): ... go.Scatter(x=[1,2,3], y=[2,1,2])]) Add two Scatter traces to vertically stacked subplots - >>> fig = tools.make_subplots(rows=2) - This is the format of your plot grid: - [ (1,1) x1,y1 ] - [ (2,1) x2,y2 ] - + >>> fig = subplots.make_subplots(rows=2) >>> fig.add_traces([go.Scatter(x=[1,2,3], y=[2,1,2]), ... go.Scatter(x=[1,2,3], y=[2,1,2])], ... rows=[1, 2], cols=[1, 1]) @@ -1608,7 +1600,7 @@ def add_traces(self, data, rows=None, cols=None, secondary_ys=None): # Update messages self._send_addTraces_msg(new_traces_data) - return data + return self # Subplots # -------- diff --git a/packages/python/plotly/plotly/graph_objs/_figure.py b/packages/python/plotly/plotly/graph_objs/_figure.py index b54dd10490b..d6b085b63b9 100644 --- a/packages/python/plotly/plotly/graph_objs/_figure.py +++ b/packages/python/plotly/plotly/graph_objs/_figure.py @@ -30,6 +30,8 @@ def __init__( that may be specified as: - A list or tuple of trace instances (e.g. [Scatter(...), Bar(...)]) + - A single trace instance + (e.g. Scatter(...), Bar(...), etc.) - A list or tuple of dicts of string/value properties where: - The 'type' property specifies the trace type One of: ['area', 'bar', 'barpolar', 'box', @@ -689,7 +691,7 @@ def add_area( Returns ------- - Area + Figure """ new_trace = Area( customdata=customdata, @@ -1073,7 +1075,7 @@ def add_bar( Returns ------- - Bar + Figure """ new_trace = Bar( alignmentgroup=alignmentgroup, @@ -1386,7 +1388,7 @@ def add_barpolar( Returns ------- - Barpolar + Figure """ new_trace = Barpolar( base=base, @@ -1755,7 +1757,7 @@ def add_box( Returns ------- - Box + Figure """ new_trace = Box( alignmentgroup=alignmentgroup, @@ -2040,7 +2042,7 @@ def add_candlestick( Returns ------- - Candlestick + Figure """ new_trace = Candlestick( close=close, @@ -2300,7 +2302,7 @@ def add_carpet( Returns ------- - Carpet + Figure """ new_trace = Carpet( a=a, @@ -2598,7 +2600,7 @@ def add_choropleth( Returns ------- - Choropleth + Figure """ new_trace = Choropleth( autocolorscale=autocolorscale, @@ -2947,7 +2949,7 @@ def add_cone( Returns ------- - Cone + Figure """ new_trace = Cone( anchor=anchor, @@ -3346,7 +3348,7 @@ def add_contour( Returns ------- - Contour + Figure """ new_trace = Contour( autocolorscale=autocolorscale, @@ -3716,7 +3718,7 @@ def add_contourcarpet( Returns ------- - Contourcarpet + Figure """ new_trace = Contourcarpet( a=a, @@ -4094,7 +4096,7 @@ def add_funnel( Returns ------- - Funnel + Figure """ new_trace = Funnel( alignmentgroup=alignmentgroup, @@ -4391,7 +4393,7 @@ def add_funnelarea( Returns ------- - Funnelarea + Figure """ new_trace = Funnelarea( aspectratio=aspectratio, @@ -4764,7 +4766,7 @@ def add_heatmap( Returns ------- - Heatmap + Figure """ new_trace = Heatmap( autocolorscale=autocolorscale, @@ -5082,7 +5084,7 @@ def add_heatmapgl( Returns ------- - Heatmapgl + Figure """ new_trace = Heatmapgl( autocolorscale=autocolorscale, @@ -5459,7 +5461,7 @@ def add_histogram( Returns ------- - Histogram + Figure """ new_trace = Histogram( alignmentgroup=alignmentgroup, @@ -5874,7 +5876,7 @@ def add_histogram2d( Returns ------- - Histogram2d + Figure """ new_trace = Histogram2d( autobinx=autobinx, @@ -6313,7 +6315,7 @@ def add_histogram2dcontour( Returns ------- - Histogram2dContour + Figure """ new_trace = Histogram2dContour( autobinx=autobinx, @@ -6673,7 +6675,7 @@ def add_isosurface( Returns ------- - Isosurface + Figure """ new_trace = Isosurface( autocolorscale=autocolorscale, @@ -7103,7 +7105,7 @@ def add_mesh3d( Returns ------- - Mesh3d + Figure """ new_trace = Mesh3d( alphahull=alphahull, @@ -7394,7 +7396,7 @@ def add_ohlc( Returns ------- - Ohlc + Figure """ new_trace = Ohlc( close=close, @@ -7607,7 +7609,7 @@ def add_parcats( Returns ------- - Parcats + Figure """ new_trace = Parcats( arrangement=arrangement, @@ -7760,7 +7762,7 @@ def add_parcoords( Returns ------- - Parcoords + Figure """ new_trace = Parcoords( customdata=customdata, @@ -8053,7 +8055,7 @@ def add_pie( Returns ------- - Pie + Figure """ new_trace = Pie( customdata=customdata, @@ -8320,7 +8322,7 @@ def add_pointcloud( Returns ------- - Pointcloud + Figure """ new_trace = Pointcloud( customdata=customdata, @@ -8518,7 +8520,7 @@ def add_sankey( Returns ------- - Sankey + Figure """ new_trace = Sankey( arrangement=arrangement, @@ -8936,7 +8938,7 @@ def add_scatter( Returns ------- - Scatter + Figure """ new_trace = Scatter( cliponaxis=cliponaxis, @@ -9266,7 +9268,7 @@ def add_scatter3d( Returns ------- - Scatter3d + Figure """ new_trace = Scatter3d( connectgaps=connectgaps, @@ -9597,7 +9599,7 @@ def add_scattercarpet( Returns ------- - Scattercarpet + Figure """ new_trace = Scattercarpet( a=a, @@ -9909,7 +9911,7 @@ def add_scattergeo( Returns ------- - Scattergeo + Figure """ new_trace = Scattergeo( connectgaps=connectgaps, @@ -10265,7 +10267,7 @@ def add_scattergl( Returns ------- - Scattergl + Figure """ new_trace = Scattergl( connectgaps=connectgaps, @@ -10564,7 +10566,7 @@ def add_scattermapbox( Returns ------- - Scattermapbox + Figure """ new_trace = Scattermapbox( connectgaps=connectgaps, @@ -10901,7 +10903,7 @@ def add_scatterpolar( Returns ------- - Scatterpolar + Figure """ new_trace = Scatterpolar( cliponaxis=cliponaxis, @@ -11243,7 +11245,7 @@ def add_scatterpolargl( Returns ------- - Scatterpolargl + Figure """ new_trace = Scatterpolargl( connectgaps=connectgaps, @@ -11586,7 +11588,7 @@ def add_scatterternary( Returns ------- - Scatterternary + Figure """ new_trace = Scatterternary( a=a, @@ -11864,7 +11866,7 @@ def add_splom( Returns ------- - Splom + Figure """ new_trace = Splom( customdata=customdata, @@ -12191,7 +12193,7 @@ def add_streamtube( Returns ------- - Streamtube + Figure """ new_trace = Streamtube( autocolorscale=autocolorscale, @@ -12474,7 +12476,7 @@ def add_sunburst( Returns ------- - Sunburst + Figure """ new_trace = Sunburst( branchvalues=branchvalues, @@ -12810,7 +12812,7 @@ def add_surface( Returns ------- - Surface + Figure """ new_trace = Surface( autocolorscale=autocolorscale, @@ -13007,7 +13009,7 @@ def add_table( Returns ------- - Table + Figure """ new_trace = Table( cells=cells, @@ -13380,7 +13382,7 @@ def add_violin( Returns ------- - Violin + Figure """ new_trace = Violin( alignmentgroup=alignmentgroup, @@ -13749,7 +13751,7 @@ def add_volume( Returns ------- - Volume + Figure """ new_trace = Volume( autocolorscale=autocolorscale, @@ -14148,7 +14150,7 @@ def add_waterfall( Returns ------- - Waterfall + Figure """ new_trace = Waterfall( alignmentgroup=alignmentgroup, diff --git a/packages/python/plotly/plotly/graph_objs/_figurewidget.py b/packages/python/plotly/plotly/graph_objs/_figurewidget.py index 0ae9705e360..3a151a723f7 100644 --- a/packages/python/plotly/plotly/graph_objs/_figurewidget.py +++ b/packages/python/plotly/plotly/graph_objs/_figurewidget.py @@ -30,6 +30,8 @@ def __init__( that may be specified as: - A list or tuple of trace instances (e.g. [Scatter(...), Bar(...)]) + - A single trace instance + (e.g. Scatter(...), Bar(...), etc.) - A list or tuple of dicts of string/value properties where: - The 'type' property specifies the trace type One of: ['area', 'bar', 'barpolar', 'box', @@ -689,7 +691,7 @@ def add_area( Returns ------- - Area + FigureWidget """ new_trace = Area( customdata=customdata, @@ -1073,7 +1075,7 @@ def add_bar( Returns ------- - Bar + FigureWidget """ new_trace = Bar( alignmentgroup=alignmentgroup, @@ -1386,7 +1388,7 @@ def add_barpolar( Returns ------- - Barpolar + FigureWidget """ new_trace = Barpolar( base=base, @@ -1755,7 +1757,7 @@ def add_box( Returns ------- - Box + FigureWidget """ new_trace = Box( alignmentgroup=alignmentgroup, @@ -2040,7 +2042,7 @@ def add_candlestick( Returns ------- - Candlestick + FigureWidget """ new_trace = Candlestick( close=close, @@ -2300,7 +2302,7 @@ def add_carpet( Returns ------- - Carpet + FigureWidget """ new_trace = Carpet( a=a, @@ -2598,7 +2600,7 @@ def add_choropleth( Returns ------- - Choropleth + FigureWidget """ new_trace = Choropleth( autocolorscale=autocolorscale, @@ -2947,7 +2949,7 @@ def add_cone( Returns ------- - Cone + FigureWidget """ new_trace = Cone( anchor=anchor, @@ -3346,7 +3348,7 @@ def add_contour( Returns ------- - Contour + FigureWidget """ new_trace = Contour( autocolorscale=autocolorscale, @@ -3716,7 +3718,7 @@ def add_contourcarpet( Returns ------- - Contourcarpet + FigureWidget """ new_trace = Contourcarpet( a=a, @@ -4094,7 +4096,7 @@ def add_funnel( Returns ------- - Funnel + FigureWidget """ new_trace = Funnel( alignmentgroup=alignmentgroup, @@ -4391,7 +4393,7 @@ def add_funnelarea( Returns ------- - Funnelarea + FigureWidget """ new_trace = Funnelarea( aspectratio=aspectratio, @@ -4764,7 +4766,7 @@ def add_heatmap( Returns ------- - Heatmap + FigureWidget """ new_trace = Heatmap( autocolorscale=autocolorscale, @@ -5082,7 +5084,7 @@ def add_heatmapgl( Returns ------- - Heatmapgl + FigureWidget """ new_trace = Heatmapgl( autocolorscale=autocolorscale, @@ -5459,7 +5461,7 @@ def add_histogram( Returns ------- - Histogram + FigureWidget """ new_trace = Histogram( alignmentgroup=alignmentgroup, @@ -5874,7 +5876,7 @@ def add_histogram2d( Returns ------- - Histogram2d + FigureWidget """ new_trace = Histogram2d( autobinx=autobinx, @@ -6313,7 +6315,7 @@ def add_histogram2dcontour( Returns ------- - Histogram2dContour + FigureWidget """ new_trace = Histogram2dContour( autobinx=autobinx, @@ -6673,7 +6675,7 @@ def add_isosurface( Returns ------- - Isosurface + FigureWidget """ new_trace = Isosurface( autocolorscale=autocolorscale, @@ -7103,7 +7105,7 @@ def add_mesh3d( Returns ------- - Mesh3d + FigureWidget """ new_trace = Mesh3d( alphahull=alphahull, @@ -7394,7 +7396,7 @@ def add_ohlc( Returns ------- - Ohlc + FigureWidget """ new_trace = Ohlc( close=close, @@ -7607,7 +7609,7 @@ def add_parcats( Returns ------- - Parcats + FigureWidget """ new_trace = Parcats( arrangement=arrangement, @@ -7760,7 +7762,7 @@ def add_parcoords( Returns ------- - Parcoords + FigureWidget """ new_trace = Parcoords( customdata=customdata, @@ -8053,7 +8055,7 @@ def add_pie( Returns ------- - Pie + FigureWidget """ new_trace = Pie( customdata=customdata, @@ -8320,7 +8322,7 @@ def add_pointcloud( Returns ------- - Pointcloud + FigureWidget """ new_trace = Pointcloud( customdata=customdata, @@ -8518,7 +8520,7 @@ def add_sankey( Returns ------- - Sankey + FigureWidget """ new_trace = Sankey( arrangement=arrangement, @@ -8936,7 +8938,7 @@ def add_scatter( Returns ------- - Scatter + FigureWidget """ new_trace = Scatter( cliponaxis=cliponaxis, @@ -9266,7 +9268,7 @@ def add_scatter3d( Returns ------- - Scatter3d + FigureWidget """ new_trace = Scatter3d( connectgaps=connectgaps, @@ -9597,7 +9599,7 @@ def add_scattercarpet( Returns ------- - Scattercarpet + FigureWidget """ new_trace = Scattercarpet( a=a, @@ -9909,7 +9911,7 @@ def add_scattergeo( Returns ------- - Scattergeo + FigureWidget """ new_trace = Scattergeo( connectgaps=connectgaps, @@ -10265,7 +10267,7 @@ def add_scattergl( Returns ------- - Scattergl + FigureWidget """ new_trace = Scattergl( connectgaps=connectgaps, @@ -10564,7 +10566,7 @@ def add_scattermapbox( Returns ------- - Scattermapbox + FigureWidget """ new_trace = Scattermapbox( connectgaps=connectgaps, @@ -10901,7 +10903,7 @@ def add_scatterpolar( Returns ------- - Scatterpolar + FigureWidget """ new_trace = Scatterpolar( cliponaxis=cliponaxis, @@ -11243,7 +11245,7 @@ def add_scatterpolargl( Returns ------- - Scatterpolargl + FigureWidget """ new_trace = Scatterpolargl( connectgaps=connectgaps, @@ -11586,7 +11588,7 @@ def add_scatterternary( Returns ------- - Scatterternary + FigureWidget """ new_trace = Scatterternary( a=a, @@ -11864,7 +11866,7 @@ def add_splom( Returns ------- - Splom + FigureWidget """ new_trace = Splom( customdata=customdata, @@ -12191,7 +12193,7 @@ def add_streamtube( Returns ------- - Streamtube + FigureWidget """ new_trace = Streamtube( autocolorscale=autocolorscale, @@ -12474,7 +12476,7 @@ def add_sunburst( Returns ------- - Sunburst + FigureWidget """ new_trace = Sunburst( branchvalues=branchvalues, @@ -12810,7 +12812,7 @@ def add_surface( Returns ------- - Surface + FigureWidget """ new_trace = Surface( autocolorscale=autocolorscale, @@ -13007,7 +13009,7 @@ def add_table( Returns ------- - Table + FigureWidget """ new_trace = Table( cells=cells, @@ -13380,7 +13382,7 @@ def add_violin( Returns ------- - Violin + FigureWidget """ new_trace = Violin( alignmentgroup=alignmentgroup, @@ -13749,7 +13751,7 @@ def add_volume( Returns ------- - Volume + FigureWidget """ new_trace = Volume( autocolorscale=autocolorscale, @@ -14148,7 +14150,7 @@ def add_waterfall( Returns ------- - Waterfall + FigureWidget """ new_trace = Waterfall( alignmentgroup=alignmentgroup,