如何生成非线性颜色图/颜色条? [英] How to generate a non-linear colormap/colorbar?

查看:82
本文介绍了如何生成非线性颜色图/颜色条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个不均匀的颜色条,如第一张图片所示.我已经尝试了下面的代码. "mycamp4"是手动保存的颜色图.结果显示为第二个数字.数字0.11.5将太封闭,也可以看到.如何使颜色条像第一张照片一样?

I would like to show a non-uniform colorbar as in the first picture. I have tried the code below. 'mycamp4' is a colormap manually saved. The result is shown as the second figure. The number 0.1 and 1.5 will be too closed too see. How can I make the colorbar like in the first picture?

v = [0.1 1 1.5 5 7.5 10 30];
v_2 = [0.1 1.5 5 7.5 10 30];
contourf(X,Y,pdf_normal',v);
h = colorbar;
load('MyColormaps','mycmap4');
set(gcf,'Colormap',mycmap4);
set(h, 'YTick', v_2)

图片1:

图片2:

推荐答案

此处有逐步的说明.

首先考虑以下示例:

[X,Y,Z1] = peaks;

figure(1)
[~,h1] = contourf(X,Y,Z1,20);
a1 = colorbar;
colormap(jet)
caxis([-6,6])

这将为您提供以下情节:

which will give you the following plot:

它具有线性数据和线性颜色图.现在,我想缩放Z -Data使其像您的情况一样呈非线性.我选择了一个简单的数据平方.

It has linear data and a linear colormap. Now I want to scale the Z-Data to get it non-linear like in your case. I chose a simple squaring of the data.

Z2 = get(h1,'ZData');
scalefactor = @(x) sign(x).*x.^2;
Z2 = scalefactor(Z2);

那是实际的示例数据,类似于您的数据:

Thats the actual example data, similar to yours:

figure(2)
[~,h2] = contourf(X,Y,Z2,20);
a2 = colorbar;
colormap(jet)
caxis([-6^2,6^2])

现在我们有了非线性数据,但仍然是线性colormapcolorbar.

Now we have non-linear data, but still a linear colormap and colorbar.

直到现在,所有操作都将生成与您的数据类似的示例数据.

现在是实际答案:

获取地块数据:

Z3 = get(h2,'ZData');

并与您希望或多或少了解的关系进行缩放:

and scale it with a relation you hopefully know more or less:

descalefactor = @(x) sign(x).*abs(x).^(1/2);
Z3 = descalefactor(Z3);

按比例绘制数据的图:

figure(3)
[~,h3] = contourf(X,Y,Z3,20);
a3 = colorbar;
colormap(jet)
caxis([-6,6])

获取Y-Ticksscale it with the inverse function,就像您的数据一样:

get the Y-Ticks and scale it with the inverse function, like your data:

ticks = get(a3,'YTick');
ticks = scalefactor(ticks);

设置这些反比例缩放的颜色条刻度:

set these inversly scaled colorbar ticks:

set(a3,'YTickLabel',ticks)

您最终得到了一个看似线性化的图(但是您可以从以前备份非线性数据),并带有一个非线性色图和色条刻度.

and you finally get a seemingly linearized plot (but you could just backup your non-linear data from before), with a with non-linear colormap and colorbar ticks.

正如预期的那样,该图看起来与第一个示例中的图相同,但是具有缩放的颜色条轴.

As expected, the plot looks the same like in the first the example, but with a scaled colorbar axis.

如果您没有任何功能上的关系,请尝试获得一个,例如与曲线拟合工具箱.

If you don't have any functional relationship, try to get one, e.g. with the curve fitting toolbox.

这篇关于如何生成非线性颜色图/颜色条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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