使用Matplotlib绘制2D热图 [英] Plotting a 2D heatmap with Matplotlib
本文介绍了使用Matplotlib绘制2D热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Matplotlib,我想绘制2D热图.我的数据是一个n×n的Numpy数组,每个数组的值都在0到1之间.因此,对于该数组的(i,j)元素,我想在我的(i,j)坐标上绘制一个正方形热图,其颜色与数组中元素的值成比例.
Using Matplotlib, I want to plot a 2D heat map. My data is an n-by-n Numpy array, each with a value between 0 and 1. So for the (i, j) element of this array, I want to plot a square at the (i, j) coordinate in my heat map, whose color is proportional to the element's value in the array.
我该怎么做?
推荐答案
<具有参数interpolation='nearest'
和cmap='hot'
的c0> 函数应该可以执行您想要的操作.
The imshow()
function with parameters interpolation='nearest'
and cmap='hot'
should do what you want.
import matplotlib.pyplot as plt
import numpy as np
a = np.random.random((16, 16))
plt.imshow(a, cmap='hot', interpolation='nearest')
plt.show()
这篇关于使用Matplotlib绘制2D热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文