Mike Nelson
Mike Nelson

Reputation: 167

Set legend from looped data points matlab

I would like to scatter plot different sets of data points. Each point should have a different markerfacecolor, but within a given set, they would all have the same markeredgecolor.

I got this to work by looping over single scatter points individually, because markerfacecolor seems to only be able to take scalar points. The way I do it is that I loop through my data, and look for the appropriate color.

This works fine because I can define each point separately, but it becomes a problem when trying to set up the legend. It tries to list all the different points, but what I'd like is just an empty circle (markerfacecolor white or transparent), with each set having their specific markeredgecolor.

I hope this is clear enough. Thank you.

Mike

Upvotes: 0

Views: 96

Answers (1)

dsgrnt
dsgrnt

Reputation: 393

I've had luck using patches, setting 'FaceColor', 'EdgeColor' to 'none', 'MarkerEdgeColor' to 'flat' and setting the 'FaceVertexCData' to a Nx3 matrix where each row is a color corresponding the the points specified by you Nx1 'XData', 'YData' and 'ZData'.

h = patch('parent',gca,...
          'XData',x,...
          'YData',y,...
          'ZData',z,...
          'FaceColor','none',...
          'EdgeColor','none',...
          'MarkerFaceColor',faceColor,...
          'MarkerEdgeColor','flat',... This is what sets the Edge of each marker
          'FaceVertexCData',C) % C is a Nx3

I don't have access to Matlab at the moment, and Octave does not seem to have exactly the same functionality. Check out the Matlab patch properties documentation for more information.

Upvotes: 0

Related Questions