使用日志颜色条通过第三个变量为 matplotlib 散点图着色

coloring matplotlib scatterplot by third variable with log color bar

我正在尝试绘制两个 arrays/lists 的散点图,其中一个是 x 坐标,另一个是 y。我对此没有任何问题。但是,我需要根据二维数组中的数据,根据特定时间点的值对这些点进行颜色编码。此外,这个 2d 数据数组的分布非常大,所以我想对数点着色(我不确定这是否意味着只是更改颜色条标签或者是否存在更根本的差异。)

到目前为止,这是我的代码:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(1)

time = #I'd like to specify time here. 

x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]

multi_array = [[1, 1, 10, 100, 1000], [10000, 1000, 100, 10, 1], [300, 400, 5000, 12, 47]]

for counter in np.arange(0, 5):
    t = multi_array[time, counter] #I tried this, and it did not work. 
    s = plt.scatter(x[counter], y[counter], c = t, marker = 's')

plt.show()

我按照我在别处看到的建议用第三个变量着色,即将颜色设置为该变量,但是当我用我的数据集尝试这样做时,我只是把所有的点都作为一种颜色,然后当我用这个模型尝试它时,它给了我以下错误:

TypeError: list indices must be integers, not tuple

有人可以帮我按照我需要的方式给我的点上色吗?

如果我理解这个问题(我不太确定),这里是答案:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure(1)

time = 2 #I'd like to specify time here. 

x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]

multi_array = np.asarray([[1, 1, 10, 100, 1000], [10000, 1000, 100, 10, 1], [300, 400, 5000, 12, 47]])
log_array=np.log10(multi_array)
s = plt.scatter(x, y, c=log_array[time], marker = 's',s=100)
cb = plt.colorbar(s)
cb.set_label('log of ...')
plt.show()

经过一些修改,并使用从 user4421975 的回答和评论中的 link 中学到的信息,我已经弄明白了。简而言之,我使用 plt.scatter 的范数 feature/attribute/thingie 来扰乱颜色并使它们成为对数。

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(1)

time = 2 

x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]

multi_array = np.asarray([[1, 1, 10, 100, 1000], [10000, 1000, 100, 10, 1], [300, 400, 5000, 12, 47]])

for counter in np.arange(0, 5):
    s = plt.scatter(x[counter], y[counter], c = multi_array[time, counter], cmap = 'winter', norm = matplotlib.colors.LogNorm(vmin=multi_array[time].min(), vmax=multi_array[time].max()), marker = 's', )

cb = plt.colorbar(s)
cb.set_label('Log of Data')

plt.show()