简体   繁体   English

如何在python中从3个数组创建颜色映射

[英]How to create colour map from 3 arrays in python

I'm trying to create a colour plot in python of two arrays t1 and t2 with the colours being set by a third one v, but I can't get the colour bar to be in terms of the v array, it is instead in terms of t1. 我正在尝试在两个数组t1和t2的python中创建一个颜色图,颜色由第三个v设置,但我无法使颜色条与v数组相关,而是在t1的条款。 This is my code: 这是我的代码:

    import matplotlib.pyplot as plt
    import numpy as np
    t1 = [75, 76, 77, 78]
    t2 = [75, 76, 77, 78]
    v = [0.5, 0.5, 0.8, 0.8]

    image_data = np.column_stack([t1, t2, v])
    plt.imshow(image_data)
    plt.colorbar()
    plt.show()

It produces this figure: 它产生了这个数字: 颜色映射不正确的颜色条

Any help would be much appreciated. 任何帮助将非常感激。

You cannot use imshow to set x and y coordinates, and color as 3rd. 您不能使用imshow设置x和y坐标,并将颜色设置为3rd。 It is to show a matrix image, where there are X*Y values, and all these values represent color. 它是显示矩阵图像,其中有X * Y值,所有这些值代表颜色。 Perhaps you want to use scatter . 也许你想使用scatter Eg you can try: 你可以尝试:

import matplotlib.pyplot as plt
t1 = [0,1,2,3]
t2 = [0, 10, 20, 30]
v = [0.5, 0.5, 0.8, 0.8]

plt.scatter(t1, t2, c=v, cmap='Greens')
plt.colorbar()
plt.show()

You can check which colormap is most suitable for you. 您可以查看哪种色彩图最适合您。

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

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