使用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 thatimsave
does not take norm as an argument but usingpyplot
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
相关问答
更多-
递归地要求所有文件(Recursively requiring all files)[2023-10-17]
只需在构造函数中传递FilesystemIterator::SKIP_DOTS标志,例如 $directory = new RecursiveDirectoryIterator(abspath . "lib/" , FilesystemIterator::SKIP_DOTS); Just pass the flag FilesystemIterator::SKIP_DOTS in the constructor, e.g ... -
尝试这样做(需要bash --version > = 4): shopt -s globstar rename -n 's/special/regular/' ** 当您的测试正常时,删除-n开关 Try doing this (require bash --version >= 4): shopt -s globstar rename -n 's/special/regular/' ** Remove the -n switch when your tests are OK There are oth ...
-
Bash脚本递归移动(Bash Script To Recursively Move)[2022-04-08]
只需mv */*.JPG /opt/data/tmp就可以完成您所要求的操作。 你的脚本有两个常见的初学者错误。 你需要在所有包含文件名的变量周围加双引号,并且你不应该使用ls来查找文件 。 就个人而言,我也建议不要在大多数脚本中使用cd 。 如果你需要循环其他脚本中的目录, for i in ./*/; do for i in ./*/; do ...那样做。 如果您需要递归任意深度嵌套的目录,请find它。 用GNU find和GNU mv , find dir -type f -name '*.JPG ... -
您的脚本目前无法运行: 该函数被定义为rec_search ,但是你似乎错误地调用了rec 你需要在“if”之后加一个空格if[[ 它也有一些其他严重的问题: for file in `ls $1`违反了“从不解析ls的输出”的建议,对于带有空格或其他空格字符的路径不起作用 你应该缩进if和for的主体以便于阅读 脚本可以像这样修复: rec() { for path; do echo "$path" if [[ -d "$path" ]]; then ...
-
将第一行更改为其他行: 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
-
最简单的方法是使用find : for i in `find $1 -type d` # Finds all the subfolders and loop. do mkdir ${i/$1/$2} # Replaces the root with the new root and creates the dir. done 通过这种方式,您可以在$ 2中重新创建$ 1的文件夹结构。 如果使用sed将旧文件夹路径替换为new,则甚至可以避免循环。 The easiest way is to use ...
-
find bar -iname "*_100.jpg" -printf 'mv %p %p\n' \ | sed 's/_100\.jpg$/_crop\.jpg/' \ | while read l; do eval $l; done find bar -iname "*_100.jpg" -printf 'mv %p %p\n' \ | sed 's/_100\.jpg$/_crop\.jpg/' \ | while read l; do eval $l; done ...