简体   繁体   English

Matplotlib:显示numpy“稀疏”数组-放大点吗?

[英]Matplotlib: Display numpy “sparse” array - Enlarge dots?

I can display numpy array easily like this: 我可以像这样轻松显示numpy数组:

plt.imshow(ary);

the problem is that the array is very sparse and I have to zoom 1-2 times to see "artefacts" or any structure. 问题是数组非常稀疏,我必须缩放1-2倍才能看到“伪像”或任何结构。 What will you recommend so that I make this more visible. 您会提出什么建议,以便我使之更加明显。 How would you manipulate the array? 您将如何操作数组? May be some trick to enlarge the dots! 可能是扩大点数的技巧! set nearby pixels in some way? 以某种方式设置附近的像素?

================================= =================================

here is my first attempt: 这是我的第一次尝试:

lst2 = np.where(ary > 0)
px = zip(lst2[0],lst2[1])
for x,y in px : ary[x-1:x+1, y-1:y+1] = ary[x,y]

My second question: would it be possible, If the values in the array are scaled to say range 0-1 or 0-255 or 0-100, to plot them with different colors or alphas in a single command? 我的第二个问题:是否有可能,如果将数组中的值缩放到0-1或0-255或0-100范围,以便在单个命令中以不同的颜色或alpha绘制它们? I can not do: 我不能做:

plt.plot(x,y, '.', markersize=7, color='blue', alpha=ary[x,y] )

because x and y are arrays themselves and alpha/color accept single value only. 因为x和y本身就是数组,并且alpha / color仅接受单个值。 Is there one line solution or I have to do a loop. 有没有一种解决方案,或者我必须做一个循环。

What about 关于什么

y, x = np.nonzero(ary)
plt.plot(x, y, '.', markersize=5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM