MATLAB Answers

Colour legend for scatter plot

115 views (last 30 days)
Adam Fitchett
Adam Fitchett on 20 Nov 2019
Commented: darova on 20 Nov 2019
I created a 2D scatter plot with the vectors X, Y and Z and the following code
scatter(X,Y,50,Z)
So that I would have X and Y plotted against one another, and Z would be represented as the graded colour of each marker. It worked fine, but I need a legend that shows the range of Z values represented by the range of marker colours. How do I make this?

  0 Comments

Sign in to comment.

Answers (1)

Ruger28
Ruger28 on 20 Nov 2019
Edited: Ruger28 on 20 Nov 2019
x = [1:50]; % fake x data
y = [1:50]; % fake y data
z = [1:50]; % "intensity"
scatter(x,y,50,z,'filled');
cb = colorbar; % creates the colorbar on side
% use caxis to change range on colorbar
caxis([10,30]); % low end is 10, high end is 30

  1 Comment

darova
darova on 20 Nov 2019
It works. I have voted for this answer

Sign in to comment.

Products


Release

R2017b