Using imagesc and scatter together

조회 수: 36 (최근 30일)
Lev Mihailov
Lev Mihailov 2020년 1월 21일
편집: Adam Danz 2020년 2월 6일
Hello! I need to impoverish these two teams and there must be 2 colorbar, how do I do this ???
x=[1:150]
y=[1:150]
z=rand(1,150) % summer
p=rand(1,150) % winter
figure(1)
imagesc(x,y ,p)
colormap(winter)
colorbar;
hold on
scatter( x,y,[],z,'d', 'filled')
colormap(summer)
colorbar;
hold off
  댓글 수: 1
Image Analyst
Image Analyst 2020년 1월 21일
What do you mean by "impoverish"? To me it means to make poorer, less wealthy, have less money, none of which seem to apply to images and scatterplots. For what it's worth, I'm attaching demos for how you can combine multiple plots or images onto a single axes.

댓글을 달려면 로그인하십시오.

답변 (1개)

Subhadeep Koley
Subhadeep Koley 2020년 2월 3일
편집: Subhadeep Koley 2020년 2월 6일
Assuming you want to display one scatter plot over one imagesc graph both having different colormap and colorbar. Give the below code a try.
close all; clc;
x = 1:150;
y = 1:150;
z = rand(1, 150);
p = rand(1, 150);
figure; ax1 = axes;
% Plot first data
imagesc(ax1, x, y ,p);
hold on;
% Plot second data
ax2 = axes;
ax2.YDir = 'reverse';
scatter(ax2, x, y, [], z, 'd', 'filled');
% Link axes
linkaxes([ax1, ax2]);
% Hide the top axes
ax2.Visible = 'off';
ax2.XTick = [];
ax2.YTick = [];
% ax2.YDir = 'reverse';
% Add differenct colormap to different data if you wish
colormap(ax1, 'winter')
colormap(ax2, 'summer')
% Set the axes and colorbar position
set([ax1,ax2],'Position', [.17 .11 .685 .815]);
cb1 = colorbar(ax1,'Position', [.05 .11 .0675 .815]);
cb2 = colorbar(ax2,'Position', [.88 .11 .0675 .815]);
hold off;
scatterOverImagesc.png
  댓글 수: 3
Subhadeep Koley
Subhadeep Koley 2020년 2월 6일
@Adam Danz Edited the answer. Thank you!
Adam Danz
Adam Danz 2020년 2월 6일
편집: Adam Danz 2020년 2월 6일
@Lev Mihailov, this answer does what you're looking for. Don't forget to accept answers to your questions to show some gratitude to the volunteers who are helping you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by