python网格数据绘图,Python中的2D网格数据可视化

I need to visualize some data. It's basic 2D grid, where each cell have float value. I know how to e.g. assign color to value and paint grid in OpenCV. But the point here is that there are so many values so it's nearly impossible to do that. I am looking for some method, where I could use gradient. For example value -5.0 will be represented by blue, 0 - black, and +5.0 as red. Is there any way to do that in Python?

Here is sample data I am talking about

A B C D

A -1.045 2.0 3.5 -4.890

B -5.678 3.2 2.89 5.78

解决方案

Matplotlib has the imshow method for plotting arrays:

from matplotlib import mpl,pyplot

import numpy as np

# make values from -5 to 5, for this example

zvals = np.random.rand(100,100)*10-5

# make a color map of fixed colors

cmap = mpl.colors.ListedColormap(['blue',

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值