Overlaying a contourf plot on a grayscale image
3 次查看(过去 30 天)
显示 更早的评论
采纳的回答
jonas
2018-10-18
编辑:jonas
2018-10-18
You can use two linked axes with different colormaps. Example:
% Axes
ax(1)=axes('color','none','xcolor','none','ycolor','none');hold on
ax(2)=axes('color','none','xcolor','none','ycolor','none','ydir','reverse');hold on
linkaxes(ax,'xy')
axis([-3 3 -3 3])
% Contour data
[X,Y,Z] = peaks;
% Image
axes(ax(2))
I = imread('cameraman.tif');
imagesc(I,'XData',[min(X(:)) max(X(:))],'YData',[min(Y(:)) max(Y(:))]);
colormap(ax(2),'gray')
% Contour
axes(ax(1))
h = contour(X,Y,peaks);hold on
colormap(ax(1),'parula')
Just make sure the axes have the same position. If you create a colorbar "outside" of the axes area, then one axis will shrink. Usually I just create the colorbar "inside" and then move it outside by adapting its position properties.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!