How to overlay two scatter plots over each other. Each with separate colour scales.

51 vues (au cours des 30 derniers jours)
I have two seperate scatter plots, attached at the bottom you can see both scatter plots as images.
I need the coloured scatter points to be over the top of the black/white scatter plot. I only need the scale for the coloured data.
How can this be achieved as they both use different colour scales?
Below is the code for each seperate scatter plot:
%Black/White scatter
figure('Name', 'CMM Data')
scatter3(cmm_xdata,cmm_ydata,cmm_zdata,[],norm_deviation,'.')
title('CMM Data')
xlim([-radius-5 radius+5])
ylim([-radius-5 radius+5])
xlabel('x (mm)')
ylabel('y (mm)')
zlabel('z (mm)')
view(2)
colormap(flipud(gray))
daspect([1 1 1])
grid('off')
hold('on')
%Coloured scatter
figure('Name', 'Sq Data')
scatter3(cci_x,cci_y,cci_z+1,60,sqcolourvalue,'filled')
colormap(jet)
c = colorbar
title('Sq Values')
xlim([-radius-5 radius+5])
ylim([-radius-5 radius+5])
xlabel('x (mm)')
ylabel('y (mm)')
zlabel('z (mm)')
view(2)
daspect([1 1 1])
grid('off')
Thanks
Joe

Réponse acceptée

Benjamin Kraus
Benjamin Kraus le 16 Nov 2020
An axes can have only one Colormap, so you have three options:
  1. Hard-code RGB color values for one (or both) of your scatter objects.
  2. Overlap two axes and make one transparent.
  3. Concatenate your two colormaps and scale your data to use different regions of the colormap.
I think option 1 is your best bet. Because you are using the colorbar for the right plot and not the left, I suggest using hard-coded RGB values for the plot on the left.
You don't provide the data, so let me give you an example of how you could do this using random data.
cdata = rand(1,25);
cmap = gray;
colorind = round(rescale(cdata, 1, height(cmap)));
rgb = cmap(colorind, :);
s1 = scatter(cos(1:25)*5+5,sin(1:25)*5+5,100,rgb,'filled');
hold on
s2 = scatter(1:10,1:10,100,rand(1,10),'filled');
colorbar
  3 commentaires
Joe Pashley
Joe Pashley le 16 Nov 2020
Had to adjust the height(cmap) code as it was having an error.
But the end result I have now is pretty good, will tinker a bit. Image attached.
Thanks for your help.
Joe
cdata = norm_deviation;
cmap = gray;
colorind = round(rescale(cdata, 1, 64));
rgb = cmap(colorind, :);
figure('Name', 'Sq Data')
s1 = scatter3(cmm_xdata,cmm_ydata,cmm_zdata,[],rgb,'.')
hold on
s2 = scatter3(cci_x,cci_y,cci_z+1,60,sqcolourvalue,'filled')
colormap(jet)
c = colorbar
c.Label.String = 'Sq (nm)'
title('Sq Data')
xlim([-radius-5 radius+5])
ylim([-radius-5 radius+5])
xlabel('x (mm)')
ylabel('y (mm)')
zlabel('z (mm)')
view(2)
daspect([1 1 1])
grid('off')
Benjamin Kraus
Benjamin Kraus le 16 Nov 2020
The height command was updated in MATLAB R2020b to accept matrices as well as tables. I suspect the issue you were having is because you are using an older release. You can replace height(cmap) with size(cmap,1) for equivalent behavior.
One thing to note: In R2019b the default size of colormaps changed from 64 to 256. If you update, your hard-coded value of 64 will cause the code to return a different picture when the default size changes.
You can update your code to work the same in both releases by doing one of these options:
  1. Passing 64 as input to the gray command to specify the size (instead of using the default).
  2. Using size(cmap,1) instead of hard-coding 64.
Option 1
cmap = gray(64);
colorind = round(rescale(cdata, 1, 64));
Option 2
cmap = gray;
colorind = round(rescale(cdata, 1, size(cmap,1)));

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by