How to I make the colorbar stay attributed to the original scatter plot after adding a plane.
3 次查看(过去 30 天)
显示 更早的评论
The following graph (first set of code) would look much better with the plane (in the second code) however when I plot them at the same time I loose the color bar for the scatter3 plot. Is there anyway I can prioritise the scatter data for the colormap? Thanks to anyone who can help :)
First plot
close all;
clear all;
hold on;
grid on;
x = [2.25
2.67
1.72
2.17
2.53
2.99
1
1.5
1.5
2
2
0.72
0.82
1.35
1.85];
z = [2891.969195
3346.172988
2354.307823
2821.188445
3210.73036
3667.803167
1694.915086
2025.363097
2336.802294
2644.227461
2886.362509
807.9313207
998.594554
1918.290754
3245.607366];
y = [1.76
2.36
1.27
1.74
2.21
2.72
1
1
1.5
1.5
2
0.7
0.82
1.11
1.38];
mu = [25.9
36.0
15.6
24.2
32.5
44.7
5.7
12.1
12.1
20.7
20.7
3.2
4.0
9.9
17.9];
% Create 3D scatter plot, colorcode the values based on mu values
scatter3(x,y,z, 40, mu, 'filled')
xlabel('Cold Flow (l/min)')
ylabel('Hot Flow (l/min)')
zlabel('Heat Transfer Coefficient (W/m^2k)')
% equate aspect ratio (if needed)
%axis equal
colormap jet
% Add colorbar if desired
cb = colorbar();
title(cb, 'Pressure Drop (mbar)')
hold on
x2 = [0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3];
y2 = [0.5
0.5
0.5
0.5
0.5
0.5
1
1
1
1
1
1
1.5
1.5
1.5
1.5
1.5
1.5
2
2
2
2
2
2
2.5
2.5
2.5
2.5
2.5
2.5
3
3
3
3
3
3];
z2 = [1285.465043
1652.954367
1870.63867
2021.18615
2133.954576
2222.745474
1463.660465
1959.756944
2273.415694
2499.69403
2674.486749
2815.441768
1551.18987
2119.923198
2491.810631
2766.276182
2981.947056
3158.241579
1605.492757
2222.664148
2634.97716
2943.842119
3189.317721
3391.81713
1643.266028
2295.721063
2738.282674
3073.380734
3341.920437
3564.939405
1671.421298
2351.049288
2817.366469
3173.358014
3460.469185
3700.158609];
scatter3(x2,y2,z2,10,'filled')
Second plot
close all;
clear all;
hold on;
grid on;
x = [2.25
2.67
1.72
2.17
2.53
2.99
1
1.5
1.5
2
2
0.72
0.82
1.35
1.85];
z = [2891.969195
3346.172988
2354.307823
2821.188445
3210.73036
3667.803167
1694.915086
2025.363097
2336.802294
2644.227461
2886.362509
807.9313207
998.594554
1918.290754
3245.607366];
y = [1.76
2.36
1.27
1.74
2.21
2.72
1
1
1.5
1.5
2
0.7
0.82
1.11
1.38];
mu = [25.9
36.0
15.6
24.2
32.5
44.7
5.7
12.1
12.1
20.7
20.7
3.2
4.0
9.9
17.9];
% Create 3D scatter plot, colorcode the values based on mu values
scatter3(x,y,z, 40, mu, 'filled')
xlabel('Cold Flow (l/min)')
ylabel('Hot Flow (l/min)')
zlabel('Heat Transfer Coefficient (W/m^2k)')
% equate aspect ratio (if needed)
%axis equal
colormap jet
% Add colorbar if desired
cb = colorbar();
title(cb, 'Pressure Drop (mbar)')
hold on
x2 = [0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3
0.5
1
1.5
2
2.5
3];
y2 = [0.5
0.5
0.5
0.5
0.5
0.5
1
1
1
1
1
1
1.5
1.5
1.5
1.5
1.5
1.5
2
2
2
2
2
2
2.5
2.5
2.5
2.5
2.5
2.5
3
3
3
3
3
3];
z2 = [1285.465043
1652.954367
1870.63867
2021.18615
2133.954576
2222.745474
1463.660465
1959.756944
2273.415694
2499.69403
2674.486749
2815.441768
1551.18987
2119.923198
2491.810631
2766.276182
2981.947056
3158.241579
1605.492757
2222.664148
2634.97716
2943.842119
3189.317721
3391.81713
1643.266028
2295.721063
2738.282674
3073.380734
3341.920437
3564.939405
1671.421298
2351.049288
2817.366469
3173.358014
3460.469185
3700.158609];
%scatter3(x2,y2,z2,10,'filled')
tri = delaunay(x2,y2);
trisurf(tri, x2, y2, z2,'FaceColor','r', 'edgecolor', 'none','FaceAlpha', [0.3]);
2 个评论
dpb
2021-11-29
reformat the Q? so is legible -- too much data to list in line; attach as .mat file instead..or dynamically generate example with code.
dpb
2021-11-29
Given the formatting didn't try to run/download but colormap applies to the axes object or specific other graphics objects that have a 'Colormap' property -- which scatter3 doesn't.
I think you'll have to use two axes here and plot each into its own then set the colormap to the axes containing the scatter plot.
回答(1 个)
Gautam
2024-2-15
Hello Imogen,
I understand that you want the “Colormap” to map only the range of values represented by the scatter plot and not consider the plane and for that you want the “Colormap” to prioritize only the data of the scatter plot.
However, since, in this case, the “Colormap” property is of the “Axes” object and not the “Scatter” object, it is not possible to have the colormap correspond only to the scatterplot.
One possible workaround for this is to adjust the data values that map to the first and last color of the “Colormap” respectively. You can do this by adjusting the “CLim” property of the “Axes”. For that, you can create a “Scatter” object corresponding to your scatter plot modifying the line that used the “scatter3()” function as
scatplot = scatter3(x,y,z, 40, mu, 'filled');
Set the “CLim” property of the parent “Axes” by adding the following lines at the end of your code
ax = scatplot.Parent;
cmap = colormap('jet');
ax.CLim = [min(mu) max(mu)];
This gives the output as shown in the figure below
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1617738/image.png)
For more information on the “Axes Properties”, refer to the “Color and Transparency” section of the MathWorks documentation page on “Axes Properties”. I am attaching the link below for your convenience.
- Axes Properties: https://www.mathworks.com/help/releases/R2021a/matlab/ref/matlab.graphics.axis.axes-properties.html?searchHighlight=axes%20properties&s_tid=doc_srchtitle
Thank You,
Gautam Murthy
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!