Colorbar not working as expected

Hi, I'm pretty new to MatLab so I'm sorry if this is quite an easy fix that I'm not spotting.
I'm trying to plot 4 variables as a 3D scattergraph with the fourth variable as a colorbar on the side. I imported all my data into variables from an Excel sheet containing all four sets of values. I'm using Temperature, Flow Rate, Gas Ratio as x,y and z and Acid Ratio as 'a'. I did this just using 'x = DOEparameters:,1);' where DOEparameters is just the name of my imported excel table.
Using 'scatter3(x,y,z,a,50,'filled');' it generated the below plot.
My 'Acid Ratio' values filling the variable 'a' are all either 2, 3 or 5. As such, why are none of my points showing up as having a value of 2?
Thanks in advance! If you need any more details please let me know!

 Accepted Answer

Star Strider
Star Strider on 15 Apr 2022
See if:
scatter3(x,y,z,50,a,'filled')
will do what you want.
The fourth argument to scatter3 is the size, and the fifth is the colour.
.

10 Comments

Thanks for the reply! It doesn't seem to work - using 'scatter3(x,y,z,50,a,'filled');' it generated this
You can see that the two points selected have different colour values but both show up as yellow.
My pleasure!
I would have to have ‘x’, ‘y’, ‘z’, and ‘a’. to determine what the problem is.
Bath Temperature Liquid Flow Rate Concentration Gas Ratio Acid Ratio
0 0.5 0.1 2 2
0 0.5 0.1 8 2
0 2 0.1 2 2
0 2 0.1 8 2
-40 1 0.1 5 2
-80 0.5 0.1 8 2
-80 2 0.1 3 2
-80 2 0.1 8 2
-80 0.5 0.1 2 2
-60 2 0.1 2 2
0 1 0.1 5 3
-40 0.5 0.1 5 3
-40 2 0.1 5 3
-40 1 0.1 2 3
-40 1 0.1 8 3
-40 1 0.1 5 3
-40 1 0.1 5 3
-80 1 0.1 3 3
0 0.5 0.1 2 5
0 0.5 0.1 8 5
0 2 0.1 2 5
0 2 0.1 8 5
-40 1 0.1 5 5
-80 0.5 0.1 2 5
-80 0.5 0.1 8 5
-80 2 0.1 3 5
-80 2 0.1 8 5
-60 2 0.1 8 5
-60 2 0.1 2 5
-60 1 0.1 2 5
These are the values I have for my DOE Parameters. Will probably be a right formatting mess but that will hopefully help you see the issue. Thanks!
There appear to be 5 columns,
Which of them are ‘x’, ‘y’, ‘z’, and ‘a’?
Jack Webb
Jack Webb on 15 Apr 2022
Edited: Jack Webb on 15 Apr 2022
Oh yeah! Apologies - I excluded 'Concentration' since this remains as 0.1 in all cases. Sorry about that, I just copied it straight from my spreadsheet. X is temperature, Y is gas ratio, Z is liquid flow rate and A is acid ratio.
The ‘2’ and ‘5’ categories appear to overplot each other, so only two categories are actually visible —
M = [0 0.5 0.1 2 2
0 0.5 0.1 8 2
0 2 0.1 2 2
0 2 0.1 8 2
-40 1 0.1 5 2
-80 0.5 0.1 8 2
-80 2 0.1 3 2
-80 2 0.1 8 2
-80 0.5 0.1 2 2
-60 2 0.1 2 2
0 1 0.1 5 3
-40 0.5 0.1 5 3
-40 2 0.1 5 3
-40 1 0.1 2 3
-40 1 0.1 8 3
-40 1 0.1 5 3
-40 1 0.1 5 3
-80 1 0.1 3 3
0 0.5 0.1 2 5
0 0.5 0.1 8 5
0 2 0.1 2 5
0 2 0.1 8 5
-40 1 0.1 5 5
-80 0.5 0.1 2 5
-80 0.5 0.1 8 5
-80 2 0.1 3 5
-80 2 0.1 8 5
-60 2 0.1 8 5
-60 2 0.1 2 5
-60 1 0.1 2 5 ];
x = M(:,1);
y = M(:,2);
z = M(:,4);
a = M(:,5);
figure
scatter3(x, y, z, 50, a, 'filled')
colormap([1 0 0; 0 1 0; 0 0 1]) % 'RGB' Colormap
colorbar
title('All')
figure
scatter3(x(a==2), y(a==2), z(a==2), 50, 'r', 'filled')
colormap([1 0 0; 0 1 0; 0 0 1])
% colorbar
title('2')
figure
scatter3(x(a==3), y(a==3), z(a==3), 50, 'g', 'filled')
colormap([1 0 0; 0 1 0; 0 0 1])
% colorbar
title('3')
figure
scatter3(x(a==5), y(a==5), z(a==5), 50, 'b', 'filled')
colormap([1 0 0; 0 1 0; 0 0 1])
% colorbar
title('5')
Looking through the matrix, this appears to colour the dots appropriately. The ‘2’ and ‘5’ categories appear to overplot each other.
.
Jack Webb
Jack Webb on 17 Apr 2022
Edited: Jack Webb on 17 Apr 2022
Oh of course - I suppose that, for example, with the condition at -80 Temperature, 2 Flow Rate and 8 Gas, there is both a point for 2 acid equivalents and 5 acid equivalents - meaning that they overlap. That was a bit silly of me. Do you have any recommendations on how I could visualise this data more effectively? Thanks for all your help so far!
My pleasure!
‘Do you have any recommendations on how I could visualise this data more effectively?’
Considering that the data are relatively sparse and likely there are not enough of them to create a surface (at least in this data set), and the (x,y) coordinates are also not unique, the only option I can think of is to use stem3 in addition to plot3 to help locate them —
M = [0 0.5 0.1 2 2
0 0.5 0.1 8 2
0 2 0.1 2 2
0 2 0.1 8 2
-40 1 0.1 5 2
-80 0.5 0.1 8 2
-80 2 0.1 3 2
-80 2 0.1 8 2
-80 0.5 0.1 2 2
-60 2 0.1 2 2
0 1 0.1 5 3
-40 0.5 0.1 5 3
-40 2 0.1 5 3
-40 1 0.1 2 3
-40 1 0.1 8 3
-40 1 0.1 5 3
-40 1 0.1 5 3
-80 1 0.1 3 3
0 0.5 0.1 2 5
0 0.5 0.1 8 5
0 2 0.1 2 5
0 2 0.1 8 5
-40 1 0.1 5 5
-80 0.5 0.1 2 5
-80 0.5 0.1 8 5
-80 2 0.1 3 5
-80 2 0.1 8 5
-60 2 0.1 8 5
-60 2 0.1 2 5
-60 1 0.1 2 5 ];
x = M(:,1);
y = M(:,2);
z = M(:,4);
a = M(:,5);
figure
stem3(x, y, z)
hold on
scatter3(x, y, z, 50, a, 'filled')
hold off
colormap([1 0 0; 0 1 0; 0 0 1]) % 'RGB' Colormap
colorbar
title('All')
I doubt that any other representation is possible.
.
Thanks, I appreciate your help!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!