Title: scatter3D assigns wrong color to points for some plot orientations · Issue #18287 · matplotlib/matplotlib · GitHub
Open Graph Title: scatter3D assigns wrong color to points for some plot orientations · Issue #18287 · matplotlib/matplotlib
X Title: scatter3D assigns wrong color to points for some plot orientations · Issue #18287 · matplotlib/matplotlib
Description: Bug report Bug summary When colors are based on coordinates in scatter3D, the color changes when the orientation of the plot is changed. Code for reproduction This codes plots 10 points along the x-axis from 0 to x_max, using scatter3D w...
Open Graph Description: Bug report Bug summary When colors are based on coordinates in scatter3D, the color changes when the orientation of the plot is changed. Code for reproduction This codes plots 10 points along the x...
X Description: Bug report Bug summary When colors are based on coordinates in scatter3D, the color changes when the orientation of the plot is changed. Code for reproduction This codes plots 10 points along the x...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/18287
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"scatter3D assigns wrong color to points for some plot orientations","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\r\nWhen colors are based on coordinates in `scatter3D`, the color changes when the orientation of the plot is changed. \r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\nThis codes plots 10 points along the x-axis from 0 to `x_max`, using `scatter3D` with their color depending on their x-position (dark purple for 0, yellow for `x_max`). The first `view_point` gives the expected result, whereas the second does not. For comparison, the same data plotted with `plot` (and offset by 1 in the z-direction for clarity) always give the expected result. \r\n\r\n```python\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimport matplotlib\r\nbackend = matplotlib.get_backend()\r\n\r\n# two view points to show the problem\r\nview_points = [[15, -70],[15, -110]]\r\n\r\n# create points along the x-axis\r\nnum_points, x_max = 10, 4\r\nx_coord = np.linspace(0, x_max, num_points)\r\ny_coord = np.zeros_like(x_coord)\r\nz_coord = np.zeros_like(x_coord)\r\n\r\ncoords_3d = np.array([x_coord, y_coord, z_coord])\r\n\r\nfor view_point in view_points:\r\n\r\n fig = plt.figure(f'view point {view_point}', clear=True)\r\n ax3d = fig.gca(projection='3d')\r\n ax3d.set_title(f'backend {backend}, view point {view_point}')\r\n \r\n ax3d.set_xlabel('x')\r\n ax3d.set_ylabel('y')\r\n ax3d.set_zlabel('z')\r\n\r\n # color points according to x-coordinate\r\n scatter = ax3d.scatter3D(*coords_3d, c=x_coord, depthshade=False)\r\n\r\n # draw same points using `plot` and offset by 1 in z-direction for clarity\r\n for coord in coords_3d.T:\r\n ax3d.plot(*coord + [0,0,1], 'x',\r\n color=scatter.cmap(scatter.norm(coord[0])) )\r\n\r\n fig.colorbar(scatter, label='x-coordinate')\r\n\r\n ax3d.view_init(*view_point)\r\n\r\n ax3d.legend(ax3d.get_children()[:2], ['scatter','plot'])\r\n fig.tight_layout()\r\n plt.show()\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n\r\nThe `view_point=[15,-110]` assigns the color in the wrong (reversed) order: the point at (0,0,0) has the bright color corresponding to an x-coordinate of `x_max`, which is clearly wrong. This occurs for azimuth angles between [-180,-90] and [90, 180] degrees.\r\n\r\n**Expected outcome**\r\n\r\n\r\n\r\nThe `view_point=[15,-70]` produces the expected outcome, i.e. dark colors for points close to the origin at (0,0,0) and bright colors for points farther away. This should be independent on the orientation of the plot.\r\n\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: maxOS 10.15.6 (19G2021)\r\n * Matplotlib version: 3.3.1\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): tested with Qt5Agg and MacOSX\r\n * Python version: 3.7.8\r\n * Jupyter version (if applicable):\r\n * Other libraries: \r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/MarkusSchwarz1980","@type":"Person","name":"MarkusSchwarz1980"},"datePublished":"2020-08-18T15:56:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/18287/matplotlib/issues/18287"}
| 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:2fe527e3-3e6b-5d91-7f90-f774bc25b0cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E386:191073:354CA4:47E334:6A5271F6 |
| html-safe-nonce | b01f96fbed6840264d76d1730c0c547e74e29d053be7f3de3e84584506fb633e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzg2OjE5MTA3MzozNTRDQTQ6NDdFMzM0OjZBNTI3MUY2IiwidmlzaXRvcl9pZCI6IjQ2MzQwOTc0Mzg3MzQ1NzgxNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7e34564f6116fd64e0816cc6d0b89a77156a6569cbcf09b79424af9f063a1a2a |
| hovercard-subject-tag | issue:681153559 |
| 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/matplotlib/matplotlib/18287/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d95696ac194962a6d8ccef9d9a8159ce29e57c795176f200f3887e9a378ad007/matplotlib/matplotlib/issues/18287 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d95696ac194962a6d8ccef9d9a8159ce29e57c795176f200f3887e9a378ad007/matplotlib/matplotlib/issues/18287 |
| og:image:alt | Bug report Bug summary When colors are based on coordinates in scatter3D, the color changes when the orientation of the plot is changed. Code for reproduction This codes plots 10 points along the x... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MarkusSchwarz1980 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width