Adding a colorbar to a figure

15 views (last 30 days)
Hi, I am trying to display a colorbar in a figure. So some background on what I am doing: I am tracking objects (from images) in 3D and in time. I wanted to just visualize the tracking so I am plotting the x and y position of an object as a circle and then color-code the circle to represent z. The way I color code is I check at what z position an object is and then assign it a color (see below).
The code is something like this:
figure;
% display the original image
imshow(image)
hold on
% loop through the data and check z position to color-code
for j = 1:n
viscircles(data(j,1:2,radius(j),'color',colors(round(data(j,3)),:));
end
where the columns in 'data' are the x, y, z positions and 'colors' is a colormap that I defined for certain z values. So I get an image something like the one attached.
So I was wondering if anyone could point me in a direction for how to add a colorbar in the figure to provide information about the z position? Any help would be greatly appreciated, thanks!

Accepted Answer

Image Analyst
Image Analyst on 16 Sep 2017
Use the colorbar(), colormap(), and caxis() functions.
  1 Comment
Yow-Ren Chang
Yow-Ren Chang on 18 Sep 2017
Thanks, creating two axes and then specifying which axis for the colorbar did the trick.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!