Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
Plotting a numpy masked array against a list of datetime objects,plt.plot
functions as expected, butplt.scatter
still displays the masked data. Auto-axis limitsdo respect the masked data though.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpy.maasmafromdatetimeimportdatetime# Create a list of datetime objectstime_unmasked= [datetime(2022,11,24,4,49,52),datetime(2022,11,24,4,49,53),datetime(2022,11,24,4,49,54),datetime(2022,11,24,4,49,55),datetime(2022,11,24,4,49,56),datetime(2022,11,24,4,49,57),datetime(2022,11,24,4,49,58)]# Create a masked array with three masked variables, one datapoint far from othersdata_masked=ma.array([15,14,50,15,15,15,16],mask=[0,0,1,1,1,0,0])# Line plot (expected behaviour)plt.plot(time_unmasked,data_masked)plt.show()# Scatter plot (plots masked points, but ignores masked values when auto-setting axis limits)plt.scatter(time_unmasked,data_masked)plt.show()
Actual outcome
plot
behaves as expected.
scatter
unexpectedly draws the masked datapoints, but axes limits are still respecting the masked array as the maskedy=50
value is not visible.
Expected outcome
Scatter should not plot the masked data even though all timestamps are unmasked.
Additional information
It seems as though there is a check withinmatplotlib.pyplot.scatter
that is not catching. I'd expect that logic to check that if eitherx
ory
were masked, to not plot that point. The datetime object is able to slip through. I've also tried puttingtime_unmasked
within a numpy masked array with the same mask asmasked_data
(so bothx
andy
have the same mask), but the same unexpected behaviour occurs.
Operating system
MacOS 11.3.1 (20E241)
Matplotlib Version
3.5.3
Matplotlib Backend
module://ipykernel.pylab.backend_inline
Python version
3.8.11
Jupyter version
5.7.10
Installation
conda