transparent background for scatter plot

조회 수: 14 (최근 30일)
Yaniv Friedman
Yaniv Friedman 2017년 10월 2일
답변: OCDER 2017년 10월 2일
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!

답변 (1개)

OCDER
OCDER 2017년 10월 2일
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

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by