plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.08k stars 2.54k forks source link

I try to annotate a 3d scatter plot and there is no ‘z’ in annotations. #2557

Closed josenxx closed 3 months ago

josenxx commented 4 years ago

ValueError Traceback (most recent call last)

in 1 data=[trace1, trace2] 2 fig=go.Figure(data=data, layout=layout) ----> 3 fig.update_layout(annotations=annotations) 4 py.iplot(fig, filename='Les-Miserables') /usr/local/anaconda3/envs/graph/lib/python3.8/site-packages/plotly/basedatatypes.py in update_layout(self, dict1, overwrite, **kwargs) 963 The Figure object that the update_layout method was called on 964 """ --> 965 self.layout.update(dict1, overwrite=overwrite, **kwargs) 966 return self 967 /usr/local/anaconda3/envs/graph/lib/python3.8/site-packages/plotly/basedatatypes.py in update(self, dict1, overwrite, **kwargs) 4198 with self.figure.batch_update(): 4199 BaseFigure._perform_update(self, dict1, overwrite=overwrite) -> 4200 BaseFigure._perform_update(self, kwargs, overwrite=overwrite) 4201 else: 4202 BaseFigure._perform_update(self, dict1, overwrite=overwrite) /usr/local/anaconda3/envs/graph/lib/python3.8/site-packages/plotly/basedatatypes.py in _perform_update(plotly_obj, update_obj, overwrite) 3305 # plotly_obj has an existing non-empty array for key 3306 # In this case we merge val into the existing elements -> 3307 BaseFigure._perform_update(plotly_obj[key], val) 3308 3309 # If update tuple is longer that current tuple, append the /usr/local/anaconda3/envs/graph/lib/python3.8/site-packages/plotly/basedatatypes.py in _perform_update(plotly_obj, update_obj, overwrite) 3337 else: 3338 update_element = update_obj[i % len(update_obj)] -> 3339 BaseFigure._perform_update(plotly_element, update_element) 3340 else: 3341 raise ValueError( /usr/local/anaconda3/envs/graph/lib/python3.8/site-packages/plotly/basedatatypes.py in _perform_update(plotly_obj, update_obj, overwrite) 3277 invalid_props = [k for k in update_obj if k not in plotly_obj] 3278 -> 3279 plotly_obj._raise_on_invalid_property_error(*invalid_props) 3280 3281 # Convert update_obj to dict /usr/local/anaconda3/envs/graph/lib/python3.8/site-packages/plotly/basedatatypes.py in _raise_on_invalid_property_error(self, *args) 4159 full_obj_name = module_root + self.__class__.__name__ 4160 -> 4161 raise ValueError( 4162 "Invalid {prop_str} specified for object of type " 4163 "{full_obj_name}: {invalid_str}\n\n" ValueError: Invalid property specified for object of type plotly.graph_objs.layout.Annotation: 'z' Valid properties: align Sets the horizontal alignment of the `text` within the box. Has an effect only if `text` spans two or more lines (i.e. `text` contains one or more
HTML tags) or if an explicit width is set to override the text width. arrowcolor Sets the color of the annotation arrow. arrowhead Sets the end annotation arrow head style. arrowside Sets the annotation arrow head position. arrowsize Sets the size of the end annotation arrow head, relative to `arrowwidth`. A value of 1 (default) gives a head about 3x as wide as the line. arrowwidth Sets the width (in px) of annotation arrow line. ax Sets the x component of the arrow tail about the arrow head. If `axref` is `pixel`, a positive (negative) component corresponds to an arrow pointing from right to left (left to right). If `axref` is an axis, this is an absolute value on that axis, like `x`, NOT a relative value. axref Indicates in what terms the tail of the annotation (ax,ay) is specified. If `pixel`, `ax` is a relative offset in pixels from `x`. If set to an x axis id (e.g. "x" or "x2"), `ax` is specified in the same terms as that axis. This is useful for trendline annotations which should continue to indicate the correct trend when zoomed. ay Sets the y component of the arrow tail about the arrow head. If `ayref` is `pixel`, a positive (negative) component corresponds to an arrow pointing from bottom to top (top to bottom). If `ayref` is an axis, this is an absolute value on that axis, like `y`, NOT a relative value. ayref Indicates in what terms the tail of the annotation (ax,ay) is specified. If `pixel`, `ay` is a relative offset in pixels from `y`. If set to a y axis id (e.g. "y" or "y2"), `ay` is specified in the same terms as that axis. This is useful for trendline annotations which should continue to indicate the correct trend when zoomed. bgcolor Sets the background color of the annotation. bordercolor Sets the color of the border enclosing the annotation `text`. borderpad Sets the padding (in px) between the `text` and the enclosing border. borderwidth Sets the width (in px) of the border enclosing the annotation `text`. captureevents Determines whether the annotation text box captures mouse move and click events, or allows those events to pass through to data points in the plot that may be behind the annotation. By default `captureevents` is False unless `hovertext` is provided. If you use the event `plotly_clickannotation` without `hovertext` you must explicitly enable `captureevents`. clicktoshow Makes this annotation respond to clicks on the plot. If you click a data point that exactly matches the `x` and `y` values of this annotation, and it is hidden (visible: false), it will appear. In "onoff" mode, you must click the same point again to make it disappear, so if you click multiple points, you can show multiple annotations. In "onout" mode, a click anywhere else in the plot (on another data point or not) will hide this annotation. If you need to show/hide this annotation in response to different `x` or `y` values, you can set `xclick` and/or `yclick`. This is useful for example to label the side of a bar. To label markers though, `standoff` is preferred over `xclick` and `yclick`. font Sets the annotation text font. height Sets an explicit height for the text box. null (default) lets the text set the box height. Taller text will be clipped. hoverlabel :class:`plotly.graph_objects.layout.annotation.Hoverlab el` instance or dict with compatible properties hovertext Sets text to appear when hovering over this annotation. If omitted or blank, no hover label will appear. name When used in a template, named items are created in the output figure in addition to any items the figure already has in this array. You can modify these items in the output figure by making your own item with `templateitemname` matching this `name` alongside your modifications (including `visible: false` or `enabled: false` to hide it). Has no effect outside of a template. opacity Sets the opacity of the annotation (text + arrow). showarrow Determines whether or not the annotation is drawn with an arrow. If True, `text` is placed near the arrow's tail. If False, `text` lines up with the `x` and `y` provided. standoff Sets a distance, in pixels, to move the end arrowhead away from the position it is pointing at, for example to point at the edge of a marker independent of zoom. Note that this shortens the arrow from the `ax` / `ay` vector, in contrast to `xshift` / `yshift` which moves everything by this amount. startarrowhead Sets the start annotation arrow head style. startarrowsize Sets the size of the start annotation arrow head, relative to `arrowwidth`. A value of 1 (default) gives a head about 3x as wide as the line. startstandoff Sets a distance, in pixels, to move the start arrowhead away from the position it is pointing at, for example to point at the edge of a marker independent of zoom. Note that this shortens the arrow from the `ax` / `ay` vector, in contrast to `xshift` / `yshift` which moves everything by this amount. templateitemname Used to refer to a named item in this array in the template. Named items from the template will be created even without a matching item in the input figure, but you can modify one by making an item with `templateitemname` matching its `name`, alongside your modifications (including `visible: false` or `enabled: false` to hide it). If there is no template or no matching item, this item will be hidden unless you explicitly show it with `visible: true`. text Sets the text associated with this annotation. Plotly uses a subset of HTML tags to do things like newline (
), bold (), italics (), hyperlinks (). Tags , , are also supported. textangle Sets the angle at which the `text` is drawn with respect to the horizontal. valign Sets the vertical alignment of the `text` within the box. Has an effect only if an explicit height is set to override the text height. visible Determines whether or not this annotation is visible. width Sets an explicit width for the text box. null (default) lets the text set the box width. Wider text will be clipped. There is no automatic wrapping; use
to start a new line. x Sets the annotation's x position. If the axis `type` is "log", then you must take the log of your desired range. If the axis `type` is "date", it should be date strings, like date data, though Date objects and unix milliseconds will be accepted and converted to strings. If the axis `type` is "category", it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears. xanchor Sets the text box's horizontal position anchor This anchor binds the `x` position to the "left", "center" or "right" of the annotation. For example, if `x` is set to 1, `xref` to "paper" and `xanchor` to "right" then the right-most portion of the annotation lines up with the right-most edge of the plotting area. If "auto", the anchor is equivalent to "center" for data- referenced annotations or if there is an arrow, whereas for paper-referenced with no arrow, the anchor picked corresponds to the closest side. xclick Toggle this annotation when clicking a data point whose `x` value is `xclick` rather than the annotation's `x` value. xref Sets the annotation's x coordinate axis. If set to an x axis id (e.g. "x" or "x2"), the `x` position refers to an x coordinate If set to "paper", the `x` position refers to the distance from the left side of the plotting area in normalized coordinates where 0 (1) corresponds to the left (right) side. xshift Shifts the position of the whole annotation and arrow to the right (positive) or left (negative) by this many pixels. y Sets the annotation's y position. If the axis `type` is "log", then you must take the log of your desired range. If the axis `type` is "date", it should be date strings, like date data, though Date objects and unix milliseconds will be accepted and converted to strings. If the axis `type` is "category", it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears. yanchor Sets the text box's vertical position anchor This anchor binds the `y` position to the "top", "middle" or "bottom" of the annotation. For example, if `y` is set to 1, `yref` to "paper" and `yanchor` to "top" then the top-most portion of the annotation lines up with the top-most edge of the plotting area. If "auto", the anchor is equivalent to "middle" for data-referenced annotations or if there is an arrow, whereas for paper- referenced with no arrow, the anchor picked corresponds to the closest side. yclick Toggle this annotation when clicking a data point whose `y` value is `yclick` rather than the annotation's `y` value. yref Sets the annotation's y coordinate axis. If set to an y axis id (e.g. "y" or "y2"), the `y` position refers to an y coordinate If set to "paper", the `y` position refers to the distance from the bottom of the plotting area in normalized coordinates where 0 (1) corresponds to the bottom (top). yshift Shifts the position of the whole annotation and arrow up (positive) or down (negative) by this many pixels. ​ ​ ​
nicolaskruchten commented 4 years ago

Yes, annotations in 3d scenes are under layout.scene.annotations. You can see an example of this here: https://plotly.com/python/text-and-annotations/#3d-annotations

chrispyles commented 4 years ago

Is it possible to do something similar with 3d subplots? I tried to use fig.update_layout but can't pass row/col as arguments and there is no fig.update_zaxes as there is with fig.update_xaxes and fig.update_yaxes. How can I individualize the z-axis names on 3D subplots?

chrispyles commented 4 years ago

Nevermind, I found a way to do it by iterating through the scene layouts in the figure (fig.select_scenes()) and editing the zaxis_title_text attribute. Might be worth adding a fig.update_zaxes method, however...

nicolaskruchten commented 4 years ago

We do have .update_scenes()...

gvwilson commented 3 months ago

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson