Azzera filtri
Azzera filtri

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

11 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

DGM
DGM il 11 Feb 2022
Modificato: DGM il 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 Commenti
DGM
DGM il 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')

Accedi per commentare.

Più risposte (1)

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

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by