# Using imagesc and scatter together

31 views (last 30 days)
Lev Mihailov on 21 Jan 2020
Edited: Adam Danz on 6 Feb 2020 at 16:23
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 Comment

Image Analyst on 21 Jan 2020
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.

Subhadeep Koley on 3 Feb 2020 at 17:24
Edited: Subhadeep Koley on 6 Feb 2020 at 16:03
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');
% 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;

Adam Danz on 6 Feb 2020 at 15:17
Nice, simple approach. Here are 3 issues, though.
linkaxes only synchronizes the axis limits. imagesc uses a reversed y axis which is why in Lev's plot, the line created by the scatter plot rises up to the left. If you were to set the ax2 color to none rather than making it invisible, you'd see that the y ticks for the two axes are in opposite order (shown below). To fix that, you either need to set the YDir for ax2 to reverse or set the YDir for ax1 to normal.
Additionally, the hold all syntax will be removed in future release so hold on is a better choice.
Lastly, the winter and summer colormaps should be switched so that winter is assigned to the imagesc plot and summer is assigned to the scatter plot.
Subhadeep Koley on 6 Feb 2020 at 16:04