Title: [Bug]: `matplotlib.pyplot.scatter` does not respect mask rules with `datetime` · Issue #24545 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `matplotlib.pyplot.scatter` does not respect mask rules with `datetime` · Issue #24545 · matplotlib/matplotlib
X Title: [Bug]: `matplotlib.pyplot.scatter` does not respect mask rules with `datetime` · Issue #24545 · matplotlib/matplotlib
Description: Bug summary Plotting a numpy masked array against a list of datetime objects, plt.plot functions as expected, but plt.scatter still displays the masked data. Auto-axis limits do respect the masked data though. Code for reproduction impor...
Open Graph Description: Bug summary Plotting a numpy masked array against a list of datetime objects, plt.plot functions as expected, but plt.scatter still displays the masked data. Auto-axis limits do respect the masked ...
X Description: Bug summary Plotting a numpy masked array against a list of datetime objects, plt.plot functions as expected, but plt.scatter still displays the masked data. Auto-axis limits do respect the masked ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24545
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `matplotlib.pyplot.scatter` does not respect mask rules with `datetime`","articleBody":"### Bug summary\r\n\r\nPlotting a numpy masked array against a list of datetime objects, `plt.plot` functions as expected, but `plt.scatter` still displays the masked data. Auto-axis limits *do* respect the masked data though.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy.ma as ma\r\nfrom datetime import datetime\r\n\r\n# Create a list of datetime objects\r\ntime_unmasked = [datetime(2022, 11, 24, 4, 49, 52),\r\n datetime(2022, 11, 24, 4, 49, 53),\r\n datetime(2022, 11, 24, 4, 49, 54),\r\n datetime(2022, 11, 24, 4, 49, 55),\r\n datetime(2022, 11, 24, 4, 49, 56),\r\n datetime(2022, 11, 24, 4, 49, 57),\r\n datetime(2022, 11, 24, 4, 49, 58)]\r\n\r\n# Create a masked array with three masked variables, one datapoint far from others\r\ndata_masked = ma.array([15,14,50,15,15,15,16], mask=[0,0,1,1,1,0,0])\r\n\r\n# Line plot (expected behaviour)\r\nplt.plot(time_unmasked, data_masked)\r\nplt.show()\r\n\r\n# Scatter plot (plots masked points, but ignores masked values when auto-setting axis limits)\r\nplt.scatter(time_unmasked, data_masked)\r\nplt.show()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n`plot` behaves as expected.\r\n\r\n[![enter image description here][1]][1]\r\n\r\n`scatter` unexpectedly draws the masked datapoints, but axes limits are still respecting the masked array as the masked `y=50` value is not visible.\r\n[![enter image description here][2]][2]\r\n\r\n\r\n\r\n [1]: https://i.stack.imgur.com/wk1FI.png\r\n [2]: https://i.stack.imgur.com/6Y6S1.png\r\n\r\n\r\n### Expected outcome\r\n\r\nScatter should not plot the masked data even though all timestamps are unmasked.\r\n[![enter image description here][3]][3]\r\n\r\n\r\n [3]: https://i.stack.imgur.com/necjd.png\r\n\r\n### Additional information\r\n\r\nIt seems as though there is a check within `matplotlib.pyplot.scatter` that is not catching. I'd expect that logic to check that if either `x` or `y` were masked, to not plot that point. The datetime object is able to slip through. I've also tried putting `time_unmasked` within a numpy masked array with the same mask as `masked_data` (so both `x` and `y` have the same mask), but the same unexpected behaviour occurs.\r\n\r\n### Operating system\r\n\r\nMacOS 11.3.1 (20E241)\r\n\r\n### Matplotlib Version\r\n\r\n3.5.3\r\n\r\n### Matplotlib Backend\r\n\r\nmodule://ipykernel.pylab.backend_inline\r\n\r\n### Python version\r\n\r\n3.8.11\r\n\r\n### Jupyter version\r\n\r\n5.7.10\r\n\r\n### Installation\r\n\r\nconda","author":{"url":"https://github.com/Benblob688","@type":"Person","name":"Benblob688"},"datePublished":"2022-11-25T11:28:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/24545/matplotlib/issues/24545"}
| 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:247c632b-7002-81d5-4227-2c3df89713f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CE7C:11A2A:A566579:A8D3256:6A50B0E6 |
| html-safe-nonce | 51bff8ec17aee0bf384eae2df2f3a74f7805aad7929895037f6d2abaf0b4973a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTdDOjExQTJBOkE1NjY1Nzk6QThEMzI1Njo2QTUwQjBFNiIsInZpc2l0b3JfaWQiOiI0NTczMDc3MzczNzc2MzQzMjcwIiwicmVnaW9uX2VkZ2UiOiJzZWEiLCJyZWdpb25fcmVuZGVyIjoic2VhIn0= |
| visitor-hmac | b8ad88dab78409f3a1ac6b07be076d923c1bfec38a31b3ebcf753cfc0424abac |
| hovercard-subject-tag | issue:1464414914 |
| 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/24545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f5d849a7458b0c75480d8b765dd567ecbfaba00677db22aaf943e1eb4ee510e/matplotlib/matplotlib/issues/24545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f5d849a7458b0c75480d8b765dd567ecbfaba00677db22aaf943e1eb4ee510e/matplotlib/matplotlib/issues/24545 |
| og:image:alt | Bug summary Plotting a numpy masked array against a list of datetime objects, plt.plot functions as expected, but plt.scatter still displays the masked data. Auto-axis limits do respect the masked ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Benblob688 |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| 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 | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width