Title: Issue when setting scatter color in separate method call · Issue #10381 · matplotlib/matplotlib · GitHub
Open Graph Title: Issue when setting scatter color in separate method call · Issue #10381 · matplotlib/matplotlib
X Title: Issue when setting scatter color in separate method call · Issue #10381 · matplotlib/matplotlib
Description: For an application I am developing, I need to call ax.scatter then change the colors of the points after the fact. However, if the input x/y values contain NaN values, then setting the colors after the fact doesn't work properly. The fol...
Open Graph Description: For an application I am developing, I need to call ax.scatter then change the colors of the points after the fact. However, if the input x/y values contain NaN values, then setting the colors after...
X Description: For an application I am developing, I need to call ax.scatter then change the colors of the points after the fact. However, if the input x/y values contain NaN values, then setting the colors after...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/10381
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Issue when setting scatter color in separate method call","articleBody":"For an application I am developing, I need to call ``ax.scatter`` then change the colors of the points after the fact. However, if the input x/y values contain NaN values, then setting the colors after the fact doesn't work properly. The following example:\r\n\r\n```python\r\nimport matplotlib\r\nmatplotlib.use('Agg')\r\n\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\nfig = plt.figure()\r\nax = fig.add_subplot(1, 1, 1, aspect='auto')\r\n\r\nx = np.array([1, 2, 3])\r\ny = np.array([2, np.nan, 4])\r\nc = np.array([3, 4, 5])\r\n\r\ns = ax.scatter(x, y, c=c, vmin=3, vmax=5, s=320, zorder=1, edgecolor='none')\r\n\r\ns = ax.scatter(x, y, s=160, zorder=2, edgecolor='none')\r\ns.set_array(c)\r\ns.set_clim(3, 5)\r\n\r\ns = ax.scatter([], [], s=40, zorder=3, edgecolor='none')\r\ns.set_offsets(np.vstack([x, y]).transpose())\r\ns.set_array(c)\r\ns.set_clim(3, 5)\r\n\r\nfig.savefig('test.png')\r\n\r\n```\r\n\r\nproduces the following output:\r\n\r\n\r\n\r\nThe top right point should be all yellow. However it isn't, because in the ``scatter`` call, invalid values are removed, so when I try and set the colors with ``set_array``, the color values are offset from the x/y values. In the final case, things work since the 'bad' values are masked from neither the offsets nor the colors.\r\n\r\nIs there a way to achieve something along the lines of the middle example (setting the colors after the fact)","author":{"url":"https://github.com/astrofrog","@type":"Person","name":"astrofrog"},"datePublished":"2018-02-05T16:02:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/10381/matplotlib/issues/10381"}
| 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:aee6c4c5-8ce5-3c69-107d-02a105c8bdcd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B824:17D477:132D2:18D43:6A52B625 |
| html-safe-nonce | 6e6b48ce84725a94577e28754b88c7f68de3005bd2cc0b2795b738107a93a676 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODI0OjE3RDQ3NzoxMzJEMjoxOEQ0Mzo2QTUyQjYyNSIsInZpc2l0b3JfaWQiOiIyMDEyNTIyNjY5MTAzMjk4MDg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 12ab8fb7a4b1b6895087fdf0be63fdb48a3ee24a916a24b5e9c780682742bd72 |
| hovercard-subject-tag | issue:294445993 |
| 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/10381/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb7179e2d2c3138978ac648e440442813fe4197c7bc89450b87812811d4ebe01/matplotlib/matplotlib/issues/10381 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb7179e2d2c3138978ac648e440442813fe4197c7bc89450b87812811d4ebe01/matplotlib/matplotlib/issues/10381 |
| og:image:alt | For an application I am developing, I need to call ax.scatter then change the colors of the points after the fact. However, if the input x/y values contain NaN values, then setting the colors after... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | astrofrog |
| 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