使用Matplotlib imshow将没有数据的点设置为白色 [英] Setting points with no data to white with Matplotlib imshow

查看:202
本文介绍了使用Matplotlib imshow将没有数据的点设置为白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlib imshow从numpy数组中绘制数据.但是,某些点中没有数据.我使用np.zeroes初始化了数组,因此这些点将拖动整个地图.我知道所有数据都不会具有0.0的值.我有什么办法告诉imshow例程忽略这些点(即,将它们留白,以便很明显它们是空的)?

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)?

推荐答案

您是否尝试使用NaN(而不是零)实例化数组,以查看matplotlib的默认设置是否会以适合您的方式忽略NaN?您还可以尝试在绘制之前仅使用逻辑索引使0的位置等于NaN.

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

或者,您可以使用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.

我认为您也可以使用该链接的想法在零位置制作一个蒙版数组,如果您不喜欢,则无需使用NaN选项.

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.

这篇关于使用Matplotlib imshow将没有数据的点设置为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆