Combination of surf and scatter plot

Hello, I would like to combine a surf and a scatter (initially contour) plot. However, I discovered that these types of plot do interact with each other, so that the plot of one type changes the color of the other. Here is an example:
n = 50;
q = linspace(-3, 3, n);
[X, Y] = meshgrid(q);
Z = peaks(X, Y);
figure(1);
surf(X, Y, Z);
hold on;
scatter3(X(:), Y(:), -10*ones(n*n, 1), [], Z(:)/10);
Does someone know how to fix this issue?

4 Comments

How do you mean: the plot of one type changes the color of the other.? You can just change the scatter-plot color and nothing changes about the surface plot? e.g.:
scatter3(X(:), Y(:), -10*ones(n*n, 1), [], Z(:)/10, 'r'); would plot the scatter plot in red?
I should have rather say colormap.
clear; close all; clc;
n = 50;
q = linspace(-3, 3, n);
[X, Y] = meshgrid(q);
Z = peaks(X, Y);
figure(1);
h = surf(X, Y, Z, 'FaceAlpha', 0.75, 'EdgeColor', 'none');
colormap gray
hold on;
scatter3(X(:), Y(:), -10*ones(n*n, 1), [], Z(:)/10);
colormap winter
check the part about supplying a target, so you can set 2 different colormaps for the different parts by supplying their handle (e.g. the h you named your surface plot).
Michael
Michael on 7 May 2020
Edited: Michael on 7 May 2020
Thanks for the suggestion. However, it didnt help. This tutorial http://www.peteryu.ca/tutorials/matlab/image_in_3d_surface_plot_with_multiple_colormaps seems to fix the issue. Since its from 2010 I thought that MATLAB already had an easier solution.

Sign in to comment.

Answers (0)

Asked:

on 7 May 2020

Edited:

on 7 May 2020

Community Treasure Hunt

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

Start Hunting!