Search code examples
matlabmatlab-figurescatter-plot

How to plot from a scatter object on Matlab


I got a scatter object and want to view it but haven't found the right function to do it. I only know that it has following properties:

         Marker: 'o'
MarkerEdgeColor: 'none'
MarkerFaceColor: [0.6350 0.0780 0.1840]
       SizeData: 36
      LineWidth: 0.5000
          XData: [1×482 double]
          YData: [1×482 double]
          ZData: [1×0 double]
          CData: [0.6350 0.0780 0.1840]

So how can I retrieve the image of this object? I know view() is for clustergram. But what function is for scatter object?


Solution

  • Matlab's scatter does not support an object as input:

    scatter(X,Y) draws the markers in the default size and color.
    scatter(X,Y,S) draws the markers at the specified sizes (S) with a single color. This type of graph is also known as a bubble plot.
    scatter(...,M) uses the marker M instead of 'o'.
    scatter(...,'filled') fills the markers.
    
    scatter(AX,...) plots into AX instead of GCA.
    
    H = scatter(...) returns handles to the scatter objects created.
    

    If you have an scatter object, you can plot it manually or reassign the parent property:

    o = scatter(rand(20,1),rand(20,1),12,lines(20),'*');
    class(o) % it's 'matlab.graphics.chart.primitive.Scatter'
    
    % manually plot the object
    figure
    scatter(o.XData,o.YData,o.SizeData,o.CData,o.Marker,'LineWidth',o.LineWidth)
    
    % or reassign the parent property
    figure
    h = axes();
    set(o,'Parent',h); % assign o's new parent.