2014-01-07 104 views
4

我遵循示例here使用gnuplot生成填充等高线图。的gnuplot的命令和输出是:等高线之间的颜色不变的填充轮廓图

reset 
f(x,y)=sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x) 
set xrange [-5:5] 
set yrange [-5:5] 
set isosample 250, 250 
set table 'test.dat' 
splot f(x,y) 
unset table 

set contour base 
set cntrparam level incremental -3, 0.5, 3 
unset surface 
set table 'cont.dat' 
splot f(x,y) 
unset table 

reset 
set xrange [-5:5] 
set yrange [-5:5] 
unset key 
set palette rgbformulae 33,13,10 
p 'test.dat' with image, 'cont.dat' w l lt -1 lw 1.5 

Filled contour plot generated using gnuplot.

此方法生成非常平滑的填充等高线图。如何修改此方法以使轮廓线之间的颜色保持不变?例如,我想为它类似于此MATLAB脚本的输出:

clc; clear all; close all; 

Nx = 250; 
Ny = 250; 
x = linspace(-5,5,Nx); 
y = linspace(-5,5,Ny); 
[X,Y] = meshgrid(x,y); 

f = sin(1.3*X).*cos(.9*Y) + cos(.8*X).*sin(1.9*Y) + cos(Y.*.2.*X); 

levels = -3:0.5:3; 
figure; 
contourf(X,Y,f,levels); 
colorbar; 

Filled contour plot generated using MATLAB.

回答

5

gnuplotset palette选项需要maxcolors设置。因此,对于你的情况,因为你有12行,你应该添加

set palette maxcolors 12 
+0

好的解决方案!您只需要增加表面的采样数量,因为填充后的轮廓不会被视为封闭的多边形,而是被拼接在一起。 – Christoph

+0

@Christoph是的,但你也有这个问题没有默认的maxcolors设置,虽然不太明显。 – Bernhard