带有 numpy 掩码数组的 Python 散点图 [英] Python scatter plot with numpy-masked arrays

查看:110
本文介绍了带有 numpy 掩码数组的 Python 散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为散点图屏蔽数据.所有数据似乎都在绘图.

I'm stuck trying to mask data for a scatter plot. All data seems to plot.

我正在使用 numpy 数组,如下面的代码片段所示.我在想,也许我无法屏蔽c"数组.我似乎找不到这样做的任何文档.我会尝试使用s"数组.

I'm using numpy arrays as shown in the snippet below. I'm thinking that perhaps I cannot mask on the "c" array. I can't seem to find any documentation for doing this. I'll try with the "s" array.

非常感谢任何帮助.

yy = NP.ma.array(yy)
xx = NP.ma.array(xx)
zz_masked = NP.ma.masked_where(zz <= 1.0e6 , zz)
scatter(xx,yy,s=15,c=zz_masked, edgecolors='none')
cbar = colorbar()
show()

推荐答案

对我有用.对 scatter() 的每次调用都会获得自己的颜色条,因为每个 scatter() 的颜色都被归一化为自己的数据.您使用的是哪个版本的 matplotlib?

Works for me. Each call to scatter() gets its own colorbar since each scatter()'s colors are normalized to its own data. Which version of matplotlib are you using?

import pylab as plt
import numpy as np

x = np.linspace(0, 1, 100)
y = x**2
z = y
z_masked = np.ma.masked_where(z > 0.5, z)

plt.scatter(x, y, c=z, s=15, edgecolors='none')
plt.colorbar()
plt.scatter(x+1, y, c=z_masked, s=15, edgecolors='none')
plt.colorbar()
plt.show()

这篇关于带有 numpy 掩码数组的 Python 散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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