Title: Improper handling of color in set_color when data contains NaN. · Issue #9891 · matplotlib/matplotlib · GitHub
Open Graph Title: Improper handling of color in set_color when data contains NaN. · Issue #9891 · matplotlib/matplotlib
X Title: Improper handling of color in set_color when data contains NaN. · Issue #9891 · matplotlib/matplotlib
Description: Bug report Bug summary When a scatter plot is made with data that contains np.nan (NaN), and then a color array is given using set_color, the wrong colors get mapped to the data points. Code for reproduction from matplotlib import pyplot...
Open Graph Description: Bug report Bug summary When a scatter plot is made with data that contains np.nan (NaN), and then a color array is given using set_color, the wrong colors get mapped to the data points. Code for re...
X Description: Bug report Bug summary When a scatter plot is made with data that contains np.nan (NaN), and then a color array is given using set_color, the wrong colors get mapped to the data points. Code for re...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/9891
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improper handling of color in set_color when data contains NaN.","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\n\r\nWhen a scatter plot is made with data that contains np.nan (NaN), and then a color array is given using `set_color`, the wrong colors get mapped to the data points.\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required--\u003e\r\n\r\n```python\r\nfrom matplotlib import pyplot\r\nfrom matplotlib.colors import Normalize\r\nfrom matplotlib import cm\r\nimport numpy as np\r\n\r\nx = np.linspace(0.0, 1.0, 50)\r\ny = np.linspace(0.0, 1.0, 50)\r\nnorm = Normalize(0.0, 1.0)\r\ncolormap = cm.ScalarMappable(norm, 'gnuplot')\r\ncolors = colormap.to_rgba(y)\r\n\r\n# Expected colors with when x and y do not contain any np.nan.\r\n# Success.\r\nplot = pyplot.scatter(x, y, color=colors)\r\npyplot.show()\r\n\r\n# Add some nan values. \r\n# If the color array is given during the initial creation of the\r\n# scatter plot, then everything works as expected.\r\n# Success.\r\nx[10:40] = np.nan\r\nplot = pyplot.scatter(x, y, color=colors)\r\npyplot.show()\r\n\r\n# Again add some nan values. \r\n# If the color array is given as a call to set_color\r\n# then the colors no longer match the data.\r\n# Failure.\r\nx[10:40] = np.nan\r\nplot = pyplot.scatter(x, y)\r\nplot.set_color(colors)\r\npyplot.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**Top:** Expected colors with when x and y do not contain any np.nan.\r\n\r\n**Middle:** Add some nan values. If the color array is given during the initial creation of the scatter plot, then everything works as expected.\r\n\r\n**Bottom:** Again add some nan values. If the color array is given as a call to `set_color` then the colors no longer match the data.\r\n\r\n\r\n\r\n\r\n\r\n**Expected outcome**\r\n\r\n\u003c!--A description of the expected outcome from the code snippet--\u003e\r\n\u003c!--If this used to work in an earlier version of Matplotlib, please note the version it used to work on--\u003e\r\n\r\nThe colors corresponding to the data points should be displayed, even when data points contain NaN and `set_color` is used.\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: OSX\r\n * Matplotlib version: 2.0.2\r\n * Matplotlib backend: module://ipykernel.pylab.backend_inline \u0026 MacOSX\r\n * Python version: 3.6.3\r\n * Jupyter Notebook version: 5.2.0\r\n * Other libraries: None\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/amicitas","@type":"Person","name":"amicitas"},"datePublished":"2017-11-30T14:30:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/9891/matplotlib/issues/9891"}
| 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:292975b8-1614-a6f0-2338-1bc2bfc98afe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F32:15CCAC:3B8C2:50179:6A521C99 |
| html-safe-nonce | 1c80d632885f82fa06cda9d498fb79bb5fdaa178c95d6b2a0f0934155db2e318 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjMyOjE1Q0NBQzozQjhDMjo1MDE3OTo2QTUyMUM5OSIsInZpc2l0b3JfaWQiOiI0NjA1NTY1NTg0NDQwMTcxNjczIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8d7483df7fff3a248a21490979d3ec4743a4c1a97dc4f44e779dfcaf9de01b0e |
| hovercard-subject-tag | issue:278139316 |
| 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/9891/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3009a0fc656b3474403213d5ac5368567ee480193fa5c2dca7c08814b94c9cb1/matplotlib/matplotlib/issues/9891 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3009a0fc656b3474403213d5ac5368567ee480193fa5c2dca7c08814b94c9cb1/matplotlib/matplotlib/issues/9891 |
| og:image:alt | Bug report Bug summary When a scatter plot is made with data that contains np.nan (NaN), and then a color array is given using set_color, the wrong colors get mapped to the data points. Code for re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | amicitas |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width