Colorbar with background image
Afficher commentaires plus anciens
Hello!
I am trying to plot some short line segments, colored by time. This works well using surf. However, I want to also have a background binary image (here, "BW") that I am plotting these segments over.
I am running into an issue where the background image changes the scaling of the colorbar, which I want to be scaled to time. I think in theory I could use clim, but I am not sure how to isolate the axes of just my segments (and not BW) since I am using surf in a for loop.
Any help would be greatly appreciated!
Thanks,
VK
% example code
figure; hold on
BW = (imbinarize(image));
imshow(BW); % background image
for i = 1:length(tracks) % plot each segment
x = [tracks(i).x]; y = [tracks(i).y]; z = [tracks(i).time];
s = surf([x(:) x(:)],[y(:) y(:)], [z(:) z(:)],...
'FaceColor','none',...
'EdgeColor','interp',...
'LineWidth',2);
end
view(2)
colorbar % very close, just need to apply the colors to the segments only and not background image...
2 commentaires
Image Analyst
il y a environ une heure
How about a screenshot of what you got and what you want?
dpb
il y a environ une heure
I would overlay two axes and then you can put the background image in the one and the surf() components in the other -- and then pass the object handles to colorbar
Réponses (2)
You can use this as a template:
% Create sample data
[X,Y] = meshgrid(linspace(-3,3,200));
A = exp(-(X.^2 + Y.^2)); % smooth Gaussian
B = sin(3*X).*cos(3*Y); % oscillatory pattern
% Plot both in overlapping axes
h1 = imagesc(A);
ax1=gca;
ax2 = axes(Position=ax1.Position);
h2 = surf(ax2,X,Y, B,'FaceAlpha',0.05,'EdgeColor','none');
colormap(ax1, gray(256))
colormap(ax2, 'parula')
axis([ax1,ax2],'off');
colorbar(ax1,'Visible','off');
colorbar(ax2);
title({'Surface B overlayed on image A', 'Colorbar corresponds to B'});
set(gcf,'Position',gcf().Position.*[1,1,1,1.2])
Voss
il y a environ une heure
tmp = arrayfun(@(x)x.time(:),tracks,'UniformOutput',false);
tmp = vertcat(tmp{:});
[z_min,z_max] = bounds(tmp);
clim([z_min,z_max])
Catégories
En savoir plus sur White dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
