transparent background for scatter plot

15 ビュー (過去 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 Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by