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

조회 수: 8 (최근 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