Title: layout subplots has implicit magic, needs a better API · Issue #1436 · plotly/plotly.py · GitHub
Open Graph Title: layout subplots has implicit magic, needs a better API · Issue #1436 · plotly/plotly.py
X Title: layout subplots has implicit magic, needs a better API · Issue #1436 · plotly/plotly.py
Description: This issue refers to the example "Stacked Subplots with a Shared X-Axis". import plotly.plotly as py import plotly.graph_objs as go trace1 = go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ) trace2 = go.Scatter( x=[2, 3, 4], y=[100, 110, 120], y...
Open Graph Description: This issue refers to the example "Stacked Subplots with a Shared X-Axis". import plotly.plotly as py import plotly.graph_objs as go trace1 = go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ) trace2 = go.Sc...
X Description: This issue refers to the example "Stacked Subplots with a Shared X-Axis". import plotly.plotly as py import plotly.graph_objs as go trace1 = go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ) trac...
Opengraph URL: https://github.com/plotly/plotly.py/issues/1436
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"layout subplots has implicit magic, needs a better API","articleBody":"This issue refers to the example \"Stacked Subplots with a Shared X-Axis\".\r\n\r\n```\r\nimport plotly.plotly as py\r\nimport plotly.graph_objs as go\r\n\r\ntrace1 = go.Scatter(\r\n x=[0, 1, 2],\r\n y=[10, 11, 12]\r\n)\r\ntrace2 = go.Scatter(\r\n x=[2, 3, 4],\r\n y=[100, 110, 120],\r\n yaxis='y2'\r\n)\r\ntrace3 = go.Scatter(\r\n x=[3, 4, 5],\r\n y=[1000, 1100, 1200],\r\n yaxis='y3'\r\n)\r\ndata = [trace1, trace2, trace3]\r\nlayout = go.Layout(\r\n yaxis=dict(\r\n domain=[0, 0.33]\r\n ),\r\n legend=dict(\r\n traceorder='reversed'\r\n ),\r\n yaxis2=dict(\r\n domain=[0.33, 0.66]\r\n ),\r\n yaxis3=dict(\r\n domain=[0.66, 1]\r\n )\r\n)\r\nfig = go.Figure(data=data, layout=layout)\r\npy.iplot(fig, filename='stacked-subplots-shared-x-axis')\r\n```\r\n\r\nFirst of all, I know that `make_subplots` abstracts a lot of this magic away, but the second I want finer control of my plot (e.g., more than just a grid or some shared axes), I need to use the layout object. \r\n\r\nThe implicit mapping of a trace from `yaxis='y2'` to the axis `yaxis2` is a bit too magical for me. The name of the axis that you give a trace doesn't match the name of the axis in the layout (`x` vs `xaxis`, `y2` vs `yaxis2`, etc.). Also, the name of the first axis doesn't have a number, e.g., `x`, `x2`, ... and `xaxis`, `xaxis2`, ... . As far as I can tell, this is only documented by example. I had to reverse engineer it from the example and by examining the layout object after much trial and error. \r\n\r\nIdeally, an axis would be a first-class object with a unique identifier. A default name like `xaxis1`, `yaxis3` is fine (as long as the naming convention is consistent for all), but it would also be nice to allow custom names that are even more meaningful. \r\n\r\nThe top-level separation between a list of traces and a layout that define a figure is confusing once subplots are involved. There is a natural relationship between a _trace_, _axes_, and _axis_. An _axes_ should have x and y (or z) _axis_. An _axes_ should have one or more _trace_ children.\r\n\r\nI'd like to see the API look more like this:\r\n\r\n```\r\nfig = go.Figure(...)\r\nax = fig.add_axes(...) . # create a custom subplot\r\nax.add_trace(go.Trace(...)) # add a trace to an axes\r\n```\r\n\r\nThere could be some convenience functions:\r\n\r\n```\r\nax = fig.axes # default axes\r\nfig.add_trace(go.Trace(...)) # equivalent to fig.axes.add_trace()\r\n\r\nax00, ax01, ax10, ax11 = fig.make_subplots(rows=2, cols=2)\r\n```\r\n\r\nOnce the API is more object-oriented, you can do cool things like add a _trace_ to more than one _axes_, and share _axis_ objects between _axes_. In the JSON representation, these would be defined once and referenced elsewhere by unique name.\r\n\r\nThese are just suggestions. Obviously there are many corner cases and backward compatibility that would have to be addressed.\r\n\r\nThe bottom line is that the current API is not intuitive and not well documented, therefore hard to use.\r\n","author":{"url":"https://github.com/jthornbrue","@type":"Person","name":"jthornbrue"},"datePublished":"2019-02-14T16:41:42Z","url":"https://github.com/plotly/plotly.py/issues/1436"}
| 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:d604fe78-5e27-07c3-9389-b0711cd07c06 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB9E:136CDA:381F03:4A8599:6B0193F4 |
| html-safe-nonce | a973b57da94f456d2903bb481316f4cd219c68bea4e74b496097405ce3276da0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjlFOjEzNkNEQTozODFGMDM6NEE4NTk5OjZCMDE5M0Y0IiwidmlzaXRvcl9pZCI6IjYwOTE4MzQyNTQxMTM3Mzk3NjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0d42936d26281547731a930cc4f0ef12b65aa12f3061851b4eb1e2a127d30dba |
| hovercard-subject-tag | issue:410390131 |
| 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/1436/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3d8aef359ce976354c497ba00fcb44377cf4ea92f10e8f61afbfc0d5c963e1a3/plotly/plotly.py/issues/1436 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3d8aef359ce976354c497ba00fcb44377cf4ea92f10e8f61afbfc0d5c963e1a3/plotly/plotly.py/issues/1436 |
| og:image:alt | This issue refers to the example "Stacked Subplots with a Shared X-Axis". import plotly.plotly as py import plotly.graph_objs as go trace1 = go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ) trace2 = go.Sc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jthornbrue |
| 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