How do you vary 2D plot color with time when X and Y data overlap?
조회 수: 17 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161880/image.jpeg)
I'm collecting data from some extensometers that show soil displacements in response to barometric pressure fluctuations. When the displacement data is plotted against the barometric data (to get a coefficient), the plot appears like a series of "squiggles" (see photo). When I use the patch() function, the polygons are filled in with color. I only want the color of the line to vary with time. Does anyone know how to accomplish this? I've tried surf(), but was unable to plot.
x = BaroP_Avg; % Barometric Pressure Data [kPa]
y = X8; % Displacement Data [microns]
col = time;
figure();patch(x,y,col);
Thanks, Rob
댓글 수: 1
Star Strider
2017년 3월 19일
Guessing on this.
Consider plotting it in 3D with time on the ‘Z’ axis, and not using patch, at least at first. Then use the view function to rotate it to view it as 2D.
There may be other approaches.
답변 (1개)
Alain Kuchta
2017년 3월 22일
I understand you would like to plot a 2D line of varying color. This MATLAB Answer suggests using surf to create the line:
https://www.mathworks.com/matlabcentral/answers/5042-how-do-i-vary-color-along-a-2d-line#answer_7057
Using the same technique, I was able to plot a line which "squiggles" back over itself and varies in color from start to finish. The one modification I made from the original post was to use "time" to vary color. The time is simply an array which increases from 1 to the number of samples.
x = [1 2 3 1 2 3];
y = [2 3 4 4 3 2];
z = zeros(size(x));
time = 1:length(x);
surface([x;x],[y;y],[z;z],[time;time],...
'facecol','no',...
'edgecol','interp',...
'linew',2);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173463/image.png)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!