我想用matplotlib在网格上绘制数据,目前正在尝试pcolormesh。 数据被组织在两个numpy数组中,数据本身和colorInformation数组。在
下面的代码绘制了数据数组(1是红色的,0是蓝色的),但是我还有一个colorInformation数组,它应该根据每个单元格的值来改变其亮度,同时保持颜色。在
例如,数据中的行[1,0,0,1]应将亮度值[0.1,0.12,0.02,0.01]应用于绘图,这样该行将可视化为[红色和亮度0.1,蓝色和亮度0.12,蓝色和亮度0.02,红色和亮度0.01]
如何做到这一点?在
import numpy as np
import matplotlib.pyplot as plt
data = np.array([[1, 0, 0, 1],
[0, 0, 1, 1],
[0, 0, 0, 1]])
colorInformation = np.array([[0.1, 0.12, 0.02, 0.01],
[0.12, 0.15, 0.18, 0.2],
[0.3, 0.34, 0.41, 0.32]])
fig, ax = plt.subplots()
heatmap = ax.pcolormesh(data)
plt.show()
我建议你自己定制颜色图来解决这个问题
或者你可以只改变红色和蓝色而不用阿尔法通道。在
相关问题 更多 >
编程相关推荐