首页 \ 问答 \ 使用Matplotlib.image自定义Colormap(Custom Colormap using Matplotlib.image)

使用Matplotlib.image自定义Colormap(Custom Colormap using Matplotlib.image)

我使用matplotlib.image.imsave('file.png',file,cmap=cmap)来保存2d Numpy数组的.png ,其中数组只能有0,1或10的值。我想要0到是白色,1是绿色,10是红色。 我在这个问题上看到了类似的东西: Matplotlib:自定义色彩图,有三种颜色 。 问题是imsave不会将规范作为参数,但使用pyplot对我的应用来说太慢了。 任何援助将不胜感激!


I am using matplotlib.image.imsave('file.png',file,cmap=cmap) to save a .png of a 2d Numpy array where the array can only have values of 0, 1 or 10. I would like 0 to be white, 1 to be green and 10 to be red. I saw something similar at this question: Matplotlib: Custom colormap with three colors . The problem is that imsave does not take norm as an argument but using pyplot is too slow for my application. Any assistance would be appreciated!


原文:https://stackoverflow.com/questions/42797220
更新时间:2023-03-06 15:03

最满意答案

将第一行更改为其他行:

sed -i '1s/.*/changed line/' *.php

在第一行之前添加一行:

sed -i '1s/^/changed line\n/' *.php

Change first line to some other line:

sed -i '1s/.*/changed line/' *.php

Adding a line before first line:

sed -i '1s/^/changed line\n/' *.php

相关问答

更多