I am graphing data from a numpy array using matplotlib imshow. However, some points have no data in them. I initialized the array using np.zeroes, so these points are dragging down the whole map. I know that none of the data will ever have a value of 0.0. Is there some way for me to tell the imshow routine to ignore these points (ie leave them white so it is clear they are empty)?
The most direct way is to just render your array to RGB using the colormap, and then change the pixels you want.
Just specify vmin=0, vmax=1 . By default, imshow normalizes the data to its min and max. You can control this with either the vmin and vmax arguments or with the norm argument (if you want a non-linear scaling).
This example displays the difference between interpolation methods for imshow . If interpolation is None, it defaults to the rcParams["image. interpolation"] (default: 'antialiased' ). If the interpolation is 'none' , then no interpolation is performed for the Agg, ps and pdf backends.
How to hide axis in matplotlib figure? The matplotlib. pyplot. axis('off') command us used to hide the axis(both x-axis & y-axis) in the matplotlib figure.
Have you tried instantiating your array with NaNs instead of zeros to see if matplotlib's default will ignore the NaNs in a way that works for you? You could also try just using logical indexing to make the locations of 0 equal to NaN right before plotting:
my_data[my_data == 0.0] = numpy.nan
Alternatively, you can use the NaN idea and follow this link's advice and use NumPy masked arrays in order to plot the NaN entries as a color you prefer.
I think you could also use that link's idea to make a masked array at the zero locations too, without going to the NaN option if you don't like it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With