叠加的热图,在蟒蛇一张图 [英] Superimpose heat maps in one plot in python

查看:356
本文介绍了叠加的热图,在蟒蛇一张图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个100×100的矩阵

I have two 100x100 matrices

u[0] and u[1]

我已经设置我的0和1之间的两个数组的值,使使用matplotlib功能的热图 pcolormesh

我能够用得到一个热图:

I am able to get one heat map by using:

 fig1=plt.pcolormesh(u[0], cmap=plt.cm.jet)

但我希望能够把在同一个人物我的两个热图,所以我可以一起查看。要做到这一点,我定义了两个数组的全球地位,它描述了阵列的质量中心,

but I want to be able to put my two heat maps on the same figure so I can view them together. To do this, I define a global position for the two arrays which describes the centre of mass of the arrays,

cm[0] and cm[1] 

我如何能实现阵列的这种相对的全球地位到一个数字,相对情节我阵列对方?

How can I implement this relative global position of the arrays onto one figure and plot my arrays relative to each other?

例如,如果

u[0]=np.array(([0,1,0],[1,1,1],[0,1,0])) is at cm=[10,20]
u[1]=np.array(([0,1,0],[1,1,1],[0,1,0])) is at cm=[40,40] 

然后记住的情节是这样的:

then the plot in mind would be something like this:

例如暗算

我想我可以用这样的:

 plt.pcolormesh(u[0], cm[0], cmap=plt.cm.jet)
 plt.pcolormesh(u[1], cm[1], cmap=plt.cm.jet)

plt.pcolormesh 不参加,很多争论。

推荐答案

您是在正确的轨道上,你只要看的手册中的 pcolormesh 多一点谨慎。您的可以的指定平面坐标为 pcolormesh

You're on the right track, you just have to look at the manual for pcolormesh a bit more carefully. You can specify in-plane coordinates for pcolormesh:

pcolormesh(X, Y, C)

本手册还提示,您可以添加一维数组作为 X ,所以你不有更动 numpy.meshgrid

所以,你应该做这样的事情:

So you should do something like this:

import matplotlib.pyplot as plt
import numpy as np

us = [np.array(([0,1,0],[1,1,1],[0,1,0])), np.array(([0,1,0],[1,1,1],[0,1,0]))]
centers = [[10,20],[40,40]]

plt.figure()
for cm,u in zip(centers,us):
    n,m = u.shape
    X = np.arange(n+1)
    Y = np.arange(m+1)
    # center and shift coordinates
    X = X - n/2.0 + cm[0]
    Y = Y - m/2.0 + cm[1]
    plt.pcolormesh(X,Y,u)

由于我们构建了 X 从数据数组的索引,每个尺寸数据热图比你们的榜样人物小得多,但可以平凡固定与 X 的Y部分比例阵列。上述code的结果是:

Since we constructed the X and Y data from the indices of the data array, the size of each "heat map" is much smaller than your example figure, but this can trivially be fixed with some scaling of the X, Y arrays. The result of the above code:

结果

这篇关于叠加的热图,在蟒蛇一张图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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