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

7 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

DGM
DGM am 11 Feb. 2022
Bearbeitet: DGM am 11 Feb. 2022
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 Kommentare
DGM
DGM am 14 Feb. 2022
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')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by