How to remove gradient line between start and end color of the colormap in filled contour plot?

7 次查看(过去 30 天)
Hi everyone!
I am trying to draw a filled contour plot but there is line (marked with black color in images attached) separating two colors of the colormap i.e start and the end which I want to remove.
I have Pcolor instead of contourf but same result and imagesc also where the line disappears but graph is doesn't appears good and I am not able to reverse the direction of Y axis in imagesc.
I am attaching output images plotted using contourf, pcolor and imagesc
Thanks!

采纳的回答

DGM
DGM 2022-2-11
编辑:DGM 2022-2-11
That's what happens when you run contour() on data with step discontinuities. If the step goes from Zmax to Zmin, then it will contain all contour lines, nonintersecting.
Since you're not actually using the contours, you might be able to just use pcolor() or image()/imagesc().
Consider the example:
x = 1:100;
y = x';
z = x+y;
z = circshift(z,[0 -30]); % create step discontinuities
nlevels = 12;
% plot using contourf
[~,hc] = contourf(x,y,z,nlevels-1);
hc.LineStyle = 'none';
colormap(hsv(nlevels))
Note the behavior at the step discontinuities
% plot using pcolor instead
figure
pcolor(x,y,z)
colormap(hsv(nlevels))
shading flat
The disadvantage to doing things this way is the lack of edge interpolation. If the data resolution is low, it might be quite pronounced.
EDIT:
I should note the banding at step discontinuities is reduced somewhat for larger arrays; however, attempting to upscale existing data with any continuous interpolant will spread out the discontinuity by at least the same factor the data is upscaled. You either have to start with fine data or use nearest-neighbor interpolation (which will make the contours jagged like using pcolor()).
  3 个评论
DGM
DGM 2022-2-14
I'm not seeing a big difference in resolution, though bear in mind, they will appear to be off by one pixel, as pcolor()/surf() centers each datapoint on the vertices, whereas image()/imagesc() center the data on the faces.
S = load('Data.mat');
data = S.data;
S = load('X.mat');
x = S.x;
S = load('Y.mat');
y = S.y;
nlevels = 24;
% using pcolor
pcolor(x,y,data)
colormap(hsv(nlevels))
shading flat
figure
% using imagesc
imagesc(x,y,data)
colormap(hsv(nlevels))
shading flat
set(gca,'ydir','normal')

请先登录,再进行评论。

更多回答(1 个)

Osman Can
Osman Can 2022-2-11
Thanks for your answer DGM. I just have the similar problem and your suggestion help to solve my issue.

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by