필터 지우기
필터 지우기

Contourf is plotting weird lines. How to remove them?

조회 수: 22 (최근 30일)
MDias
MDias 2020년 5월 22일
댓글: MDias 2020년 5월 23일
Hi,
I'm using hist3 to get bin centers and the elements in each bin. After this I use contourf to plot the data. Unfortunatelly the outputed contour figure has small vertical and horizointal black lines that don't seem to make sense. Please see lines inside red circles for examples:
My code is as follows:
edges = {0:0.2:13 0:0.2:13}; % edges for hist3
insetPos = [.52 .53 .35 .35];
[n,c] = hist3(X,'edges',edges);
figure
heatmap(n) % FEX
% contourmap
axes('Position',insetPos)
box on
contourf(c{1},c{2},n)
I belive the black lines are part of the contour lines, yet they appear where there are no boundries. If I remove the contour lines they also go away.
contourf(c{1},c{2},n,'LineColor','none') % no contour lines
Any tip on how I could keep the contour lines without drawing the "intruding" lines?
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 5월 22일
can you attach X for testing?
MDias
MDias 2020년 5월 22일
Here is a .mat file with X. Thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

Kelly Kearney
Kelly Kearney 2020년 5월 22일
When you let contour choose contour levels automatically, it doesn't always choose the levels you really want. In this case, it chooses integer values, which may not be the best way to contour all-integer data. You might have better luck getting the look you want if you specify between-integer levels, e.g.
contourf(c{1}, c{2}, n, -0.5:10.5)
  댓글 수: 1
MDias
MDias 2020년 5월 23일
Thanks Kelly!
Like Walter pointed out I didn't carefully at n...or at contourf for that matter. This does what I need.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KSSV
KSSV 2020년 5월 22일
Use pcolor with shading interp instead of contourf.
  댓글 수: 3
KSSV
KSSV 2020년 5월 22일
On this use holdon and plot contour lines using countour.
MDias
MDias 2020년 5월 22일
The unwanted bits of the contour (small black lines highlighted above) are still there.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2020년 5월 22일
Look at n(24,9) and see that it is 1 there, corresponding to x=1.7, y=4.7; n(23,9) is also 1. That is an island of two 1's surrounded by 0's. With the contour levels happening to correspond to the integers, there should be an island there.
spy(n) and you will see there are a number of small islands.
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 5월 23일
if you take
n.*bwareafilt(n>0,[SIZE, inf])
then it would filter out islands smaller than SIZE pixels
MDias
MDias 2020년 5월 23일
Thanks Walter!
Now this makes sense, I did not look carefully at n...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by