transparent background for scatter plot
14 views (last 30 days)
Show older comments
Hi,
I am presenting an image using imagesc, and I want to draw a scatter plot on top of the figure, without changing the background, and without it auto-scaling.
for example:
a = rand(100,200); % the image to be presented...
imagesc(a)
hold on
scatter(1:100,1:100,30,1:100,'filled')
hold off
if you run the code, you can see that when the scatter is being ploted, the image (a) is changed. how can I prevent that (and keep the same colormap for the scatter points)?
Thanks!
0 Comments
Answers (1)
OCDER
on 2 Oct 2017
imagesc will use the colormap of the figure, so if you want to use a different color scheme for scatter, calculate out the rgb values to use. See the sample code to see how 2 color schemes can be used:
A = rand(100,200); % the image to be presented...
HotClr = hot; %Mx3 rgb matrix for hot color scheme (for imagesc)
CoolClr = cool; %Mx3 rgb matrix for cool color scheme (for scatter)
imagesc(A) %will autoscale image according to FIGURE's ColorMap
colormap(gcf, HotClr); %setting figure colormap to hot color scheme
hold on
CoolIdx = ceil(linspace(1, size(CoolClr, 1), 100)); %find index of the different color map
scatter(1:100,1:100,30,CoolClr(CoolIdx,:),'filled'); %use the RGB values per dot instead of figure colormap index.
hold off
0 Comments
See Also
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!