Color Contours along a Line

조회 수: 4 (최근 30일)
Cliff
Cliff 2013년 2월 26일
Hello, I'm trying to create color contours along a straight line, yet I'm running into a lot of difficulty. I want to specify an x-coordinate and y-coordinate at the beginning and end of some line and then have a different color show up on that line based on some relative values. For example, I have a line from [0,-15] to [4,15] and would like to contour a color based on the fact that at [0,-15] I have a value 0.75 and at [4,15] I have a value of 0.25. I have been trying to use the built-in Matlab function 'contour' but have been unsuccesful as the Z data (i.e., my 0.75 and 0.25) is required to be a minimum of a 2x2 matrix.
Any help would be greatly appreciated, even if the best answer is "you can't do that with the 'contour' function"...
Thanks in advance!
~Cliff

채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 26일
You can't do that with contour.
What you are asking for is not contour but color interpolation. Ordinary MATLAB line and lineseries objects (such as are created by plot()) cannot have multiple colors.
Probably the easiest method to achieve the effect you want is to patch() between the two points, setting cdata to the colors you want, and setting EdgeColor to 'interp'. You might find it easiest to use explicit Vertex and Face specification:
patch('Vertices', [0 -15; 4 15], 'Faces', [1 2], 'FaceVertexCData', [0.75; 0.25], 'EdgeColor', 'interp')
  댓글 수: 2
Cliff
Cliff 2013년 2월 26일
Thanks Walter! This is a big help!
~Cliff
Cliff
Cliff 2013년 2월 27일
This is actually working pretty well; thanks again! One follow-up question: I'm trying to change the line thickness by adding (...,'LineWidth',5) to the code you have above, but that doesn't seem to work. If I swap 'interp' to 'flat', then I get the increased line width, but obviously not the color interpolation that I want. Is this a limitation in Matlab or am I doing someting incorrectly?
Thanks again,
~Cliff

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

추가 답변 (0개)

카테고리

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