フィルターのクリア

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

11 ビュー (過去 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 Center および File ExchangeContour Plots についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by