필터 지우기
필터 지우기

Change Default White for Zero in Contour Plot

조회 수: 18 (최근 30일)
Amanda
Amanda 2012년 11월 27일
댓글: Walter Roberson 2016년 8월 2일
How can I change the default white for zero for the output of a contour plot to a different color?
longitude = [80 82 95]
latitude = [30 32 35]
temp = [0 0 0; 0 0 0; 0 0 0]
contourf(longitude,latitude,temp)
Thanks,
Amanda

채택된 답변

Matt Fig
Matt Fig 2012년 11월 27일
That produces no contour plot at all...
C = contourf(longitude,latitude,temp)
Warning: Contour not rendered for constant ZData
> In contourf>parseargs at 455
In contourf at 55
C =
[]
An empty C means nothing was produced. To see that there is nothing there (not just some white contours), do this:
set(gca,'color','k')
  댓글 수: 1
Amanda
Amanda 2012년 11월 27일
Thanks. You have always helped me out.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 11월 27일
contourf() does not default to white for 0. contourf() defaults to the first entry in the active colormap for the smallest value in the data. If that smallest value happens to be 0, then you can change the color by changing the colormap. For example,
colormap(hot)
  댓글 수: 2
Amanda
Amanda 2012년 11월 27일
Walter,
But when I have an array of all zeros it is white, but 0.00001 is colored in. How can I get around this?
Amanda
Walter Roberson
Walter Roberson 2012년 11월 27일
You don't. If your array is constant data, contourf() will not plot it at all. You need to use at least two distinct values.
Are you really trying to plot a contour for an all-zero matrix, or are you trying to plot the z=0 plane to add to an existing contour plot?

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


houda
houda 2016년 8월 2일
Hi,
I have the same problem. I have a matrix which change value, so when it contains non constant value it is okay, but when it contains the same value (1 or 0) I want to have either the color corresponding to 1 or to 0. I know that the problem is that contourf don't calculate it that is why I have nothing, but there is any other function to have what I want ?
Thank you for your help!
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 8월 2일
image() the constant array if length(unique(TheArray(:)))==1

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

카테고리

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