Title: The selectedpoints attribute for Histogram plots is being set incorrectly · Issue #2698 · plotly/plotly.py · GitHub
Open Graph Title: The selectedpoints attribute for Histogram plots is being set incorrectly · Issue #2698 · plotly/plotly.py
X Title: The selectedpoints attribute for Histogram plots is being set incorrectly · Issue #2698 · plotly/plotly.py
Description: I am working in a Jupyter notebook and when accessing the selectedpoints attribute of a go.Histogram or the points list in the on_selection callback, the list does not contain integer indices of the selected points but instead just a lis...
Open Graph Description: I am working in a Jupyter notebook and when accessing the selectedpoints attribute of a go.Histogram or the points list in the on_selection callback, the list does not contain integer indices of th...
X Description: I am working in a Jupyter notebook and when accessing the selectedpoints attribute of a go.Histogram or the points list in the on_selection callback, the list does not contain integer indices of th...
Opengraph URL: https://github.com/plotly/plotly.py/issues/2698
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The selectedpoints attribute for Histogram plots is being set incorrectly","articleBody":"I am working in a Jupyter notebook and when accessing the `selectedpoints` attribute of a `go.Histogram` or the points list in the `on_selection` callback, the list does not contain integer indices of the selected points but instead just a list of objects.\r\n\r\n```python\r\nimport plotly.graph_objects as go\r\nimport numpy as np\r\n\r\nnp.random.seed(1)\r\nx = np.random.randn(500)\r\n\r\ndef on_selection_print(obj, points, selector):\r\n print(points.point_inds)\r\n\r\nfigure_widget = go.FigureWidget(data=[go.Histogram(x=x)])\r\nfigure_widget.update_layout(dragmode=\"select\") \r\nfigure_widget.data[0].on_selection(on_selection_print)\r\nfigure_widget\r\n```\r\n\r\nWhen selecting points in the histogram, the output looks something like:\r\n`[\u003cobject object at 0x7ff062c497f0>, \u003cobject object at 0x7ff062c497f0>, \u003cobject object at 0x7ff062c497f0>, \u003cobject object at 0x7ff062c497f0>, \u003cobject object at 0x7ff062c497f0>, \u003cobject object at 0x7ff062c497f0>]`\r\n\r\nA call to `figure_widget.data[0].selectedpoints` returns the same list.\r\n\r\nThe expected output would be something like:\r\n`[0, 12, 13, 26, 31, ..., 2534]`\r\n\r\nAs you can see, all objects are identical (memory address `0x7ff062c497f0`) and the objects in the list do not have any attributes. The length of the list corresponds to the number of bars selected if that helps.\r\n\r\nI am working with plotly version `4.9.0`, ipywidgets version `7.5.1` and notebook version `6.0.1`.\r\n\r\n**UPDATE**:\r\nI checked how Plotly.js handles selection for histograms and found that it creates an object for each selected bar, which in turn contains all the points for that bar.\r\ne.g.\r\n```javascript\r\n{\r\n points: [\r\n 0: {..., pointIndices: [1,2,3,4], ...},\r\n 1: {..., pointIndices: [5,6,7,8,9], ...},\r\n ...\r\n ],\r\n range: [...]\r\n}\r\n```\r\nCodepen can be found here: https://codepen.io/meffmadd/pen/zYqGmaw\r\n\r\nSo the problem seems to be that the points are not correctly serialised for histograms. Without understanding the whole codebase I think there seem to be two options:\r\n1. Update the setter to `_js2py_pointsCallback` when the figure is a histogram in https://github.com/plotly/plotly.py/blob/efc66509526bdde772e8a8caaf1bcee865ccec3a/packages/javascript/plotlywidget/src/Figure.js#L1134\r\n2. Updating the model for the histogram on the Python side to reflect the behaviour of the JavaScript implementation. I don't know how exactly this would work yet.\r\n\r\nAny pointers in the right direction are highly appreciated!\r\n","author":{"url":"https://github.com/meffmadd","@type":"Person","name":"meffmadd"},"datePublished":"2020-08-10T10:51:17Z","url":"https://github.com/plotly/plotly.py/issues/2698"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0c0becc1-3955-a3e7-2641-cb760df739cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD7A:DA744:1803516:2045A84:6B0151A1 |
| html-safe-nonce | 214099de7b3378791ee52c441260fc150ce07e4b14560b4d3595b6570265e902 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDdBOkRBNzQ0OjE4MDM1MTY6MjA0NUE4NDo2QjAxNTFBMSIsInZpc2l0b3JfaWQiOiI3NjIwNTM5NzI2MTAxMDQxNTcwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3551557caba0787221ae420d27035e7631097427dd4dadd6e6b88a51dd9d7da5 |
| hovercard-subject-tag | issue:676044655 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.py/2698/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8ebf6fbfd1a00ea95c4fd4d5f82bc003dab2f069c0aca78138a6c93ec4e3776d/plotly/plotly.py/issues/2698 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8ebf6fbfd1a00ea95c4fd4d5f82bc003dab2f069c0aca78138a6c93ec4e3776d/plotly/plotly.py/issues/2698 |
| og:image:alt | I am working in a Jupyter notebook and when accessing the selectedpoints attribute of a go.Histogram or the points list in the on_selection callback, the list does not contain integer indices of th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | meffmadd |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/plotly/plotly.py git https://github.com/plotly/plotly.py.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 14579099 |
| octolytics-dimension-repository_nwo | plotly/plotly.py |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14579099 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.py |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width