Plot (x,y,z) triplets over coordinates (x,y) with color z

前端 未结 2 364
自闭症患者
自闭症患者 2020-12-21 04:49

I\'ve got a list of points (x,y,z) and would like to visualize them as a curve on a plane with points on (x,y) and any of color/intensity/thickness as z. How can this be don

相关标签:
2条回答
  • 2020-12-21 05:17

    Assuming you don't care about the color of the actual line, but the markers. Use plot in combination with scatter.

    Imagine following example data:

    t = 0:pi/20:2*pi;
    x = sin(t);
    y = cos(t);
    z = t;
    
    plot3(x,y,z);
    

    enter image description here

    Plotted in the 2D-plane:

    plot(x,y); hold on
    scatter(x,y,300,z); hold off
    

    results in:

    enter image description here

    From your comment: if you have enough data and you don't need the line, just use scatter, it's exactly what you need.


    Another possibility inspired by a solution on MATLAB Central, considering both line and markers.

    surface([x;x],[y;y],zeros(2,length(t)),[z;z],'EdgeColor','flat',...
            'Marker','o','MarkerSize',10,'MarkerFaceColor','flat');
    

    enter image description here


    Make the color dependent on z is quite easy, for changing marker sizes you definitely need the scatter function:

    surface([x;x],[y;y],zeros(2,length(t)),[z;z],'EdgeColor','flat'); hold on
    MarkerSize = round(z*1000)+1;
    scatter(x,y,MarkerSize,z,'.','MarkerFaceColor','auto'); hold off
    

    enter image description here

    For on z depending, increasing transparency it's a little tricky. You can find a workaround here, using the patch function.

    0 讨论(0)
  • 2020-12-21 05:43

    The solution can be like that

    x = 0:.05:2*pi;
    y = cos(x);
    planez = zeros(size(x));
    z = x;  % This is the color, vary with x in this case, but you can use your vector
    surface([x;x],[y;y],[planez;planez],[z;z],...
            'facecol','no',...
            'edgecol','interp',...
            'linew',2);
    

    The point is that you are painting a surface, where the colors can easily modified. I dont think it can be done with plot

    enter image description here

    0 讨论(0)
提交回复
热议问题