how can i plot a contour plot over a imagesc?

43 ビュー (過去 30 日間)
Mel Lin
Mel Lin 2017 年 8 月 22 日
回答済み: Mohamed Ahmed 2021 年 9 月 13 日
how can i plot a contour plot over a imagesc?

回答 (2 件)

Akira Agata
Akira Agata 2017 年 8 月 23 日
The solution would be as follows:
I think you should adjust 'LineColor' to clearly visualize your contour plot over imagesc.
% Sample data
z = peaks;
% contour over imagesc
figure
imagesc(z);
hold on;
contour(z,'LineColor','w');
  2 件のコメント
Mel Lin
Mel Lin 2017 年 8 月 23 日
hello Akira, when I plot the contour plot on top of the imagesc it changes my image plot to consist of only one color instead of the full range of colors that it had prior to added the contour plot. how do i fix this Thanks!
Akira Agata
Akira Agata 2017 年 8 月 25 日
Hi Mel-san, I think that is due to the range difference. When range of image plot data (for example, z1 in the following code) and contour data ( z2 ) is different, and try to display in one figure, then colorbar range will be set to cover both image and contour data.
So, please set colorbar range explicitly by using caxis function. The following is one example and I hope it will solve your problem ! :-)
% Sample data
z1 = peaks;
z2 = 50+z1;
% contour over imagesc
figure
imagesc(z1);
cRange = caxis; % save the current color range
hold on;
contour(z2,'LineColor','w');
caxis(cRange); % set the color range to the previous one

サインインしてコメントする。


Mohamed Ahmed
Mohamed Ahmed 2021 年 9 月 13 日
%check out this Code for imagesc overlaid by contour lines
figure;
z = peaks;
imagesc(z)
axis xy; % Imagesc starts at the bottom of figure need for a flip
h_ax = gca;
h_ax.Colormap = cool;
h_ax_c = axes('position', get(h_ax, 'position'), 'Color', 'none');
contour(h_ax_c, z, [-8:2:10], 'ShowText', 'on');
h_ax_c.Color = 'none';
h_ax_c.Colormap = autumn;
h_ax_c.XTick = [];
h_ax_c.YTick = [];
title('Colormap Cool')

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by