如何使用从数组读取的颜色绘制例如正方形的 xy 网格
我有单独的 x 和 y 坐标数组,以及相应值的 z 数组。我希望制作一个在每个 x 和 y 坐标处都有正方形的图,这些正方形具有从 z 数组设置的颜色 - 类似于
I have separate arrays of x and y coordinates, and a z-array of corresponding values. I wish to make a plot that has squares at each x and y coordinate that have colours set from the z array - something similar to this. I have searched quite hard on google to find how I can do this, but to no avail. The matplotlib.pyplot.scatter function needs the color array scaled from 0-1, so I can't see how that could be used in this circumstance. Any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢安德鲁。我现在明白这是如何运作的了。问题是我的 z 数组只是一列数字。由于它们没有任何合理的顺序,因此很难将数组重新整形为 2D 来使用 pcolor。
我想出了一个更好的解决方案,使用 for 循环将矩形补丁附加到补丁集合中,然后将颜色图分配给整个集合和绘图。
Thanks Andrew. I see how that works now. The thing is my z-array is just one column of numbers. Since they are not in any sensible order, it would be difficult to just re-shape the array into 2D to use pcolor.
I have come up with a much better solution using a for loop to append rectangle patches to a patch collection, then assign a colour map to the whole collection and plot.
我猜你想要
pcolor
,如此处所示。I guess you want
pcolor
, as shown here.您需要使用这个精确的代码执行类似的操作,
最后一个点将偏离轴,但它应该给您一个想法。
You need to do something like this
with this precise code the last point will be off the axis, but it should give you the idea.