色彩图三种颜色 [英] Colormap three colors

查看:98
本文介绍了色彩图三种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个netcdf文件,其中有正电流和负电流(分别是上升流和下降流).我想创建一个轮廓线,其中下移为绿色,上移为红色,0为黑色.到目前为止,这是我的代码,其中包括Mathworks网站上的一些代码 https://nl.mathworks.com/matlabcentral/answers/81352-colormap-with-both-positive-and-negative-values :

I have a netcdf file with positive and negative currents (upwelling and downwelling respectively). I want to create a contourf where downwelling is green, upwelling is red and 0 is black. So far this is my code including some code from the Mathworks website https://nl.mathworks.com/matlabcentral/answers/81352-colormap-with-both-positive-and-negative-values :

%open netcdf file
ncdisp('20110810_061103.nc');
ncdisp('grid.nc');

latu=ncread('grid.nc','latitude_u');
lonu=ncread('grid.nc','longitude_u');
latv=ncread('grid.nc','latitude_v');
lonv=ncread('grid.nc','longitude_v');
u = ncread('20110810_061103.nc','vel_u'); %x axes velocity of water
v  = ncread('20110810_061103.nc','vel_v');%y axes
w  = ncread('20110810_061103.nc','w');%z axes 

Minu=min(min(min(u)))
Minv=min(min(min(v)))
Minw=min(min(min(w)))

Maxu=max(max(max(u)))
Maxv=max(max(max(v)))
Maxw=max(max(max(w)))

figure

contourf(lonu(1:681,1:711),latu(1:681,1:711),w(1:681,1:711,20))
%code I copied from mathworks    
greenColorMap = [zeros(1, 132), linspace(0, 1, 124)];
redColorMap = [linspace(1, 0, 124), zeros(1, 132)];
colorMap = [redColorMap; greenColorMap; zeros(1, 256)]';

% Apply the colormap.
colormap(colorMap);
colorbar

如您所见,黑色不是0.如何确定黑色为零,向下(-)为红色,向上(+)为绿色?很抱歉,如果这是重复的.我检查了问题 MATLAB:生成给定三种颜色的颜色图,但我没有不了解如何设置颜色,它会产生类似于上图的内容.以下内容与我的问题无关,尽管它具有相同的标题 Matplotlib:具有以下内容的自定义颜色图:三种颜色. 预先感谢您提供任何答案.

As you can see, the black is not at 0. How do I make sure that black is zero, downwelling (-) is red and upwelling(+) is green? I'm sorry if this is a duplicate. I checked question MATLAB: generating a colormap given three colors but I don't understand how you set the colors and it creates something similar to the above picture. The following has nothing to do with my question although it has the same title Matplotlib: Custom colormap with three colors . Thank you in advance for any answers.

推荐答案

问题不在于颜色图不正确,而在于数据值映射到颜色图的方式.这是通过以相对于零对称的方式更改基础axes对象的CLim属性来实现的,例如 set(gca,'CLim',[-1e-2 1e-2])

The issue is not with the colormap being wrong, but with the way the data values are mapped to the colormap. This is achieved by changing the CLim property of the underlying axes object with something symmetric with respect to zero, e.g. set(gca,'CLim',[-1e-2 1e-2])

这也可以通过UI交互地更改:图形菜单中的 Edit -> Colormap ... .然后编辑最小/最大颜色数据.

This can also be changed interactively through the UI: Edit -> Colormap... in the figure menu. Then edit color data min/max.

这篇关于色彩图三种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆