フィルターのクリア

3D stem plot colored by Z-value

36 ビュー (過去 30 日間)
Marco
Marco 2018 年 8 月 12 日
コメント済み: dpb 2018 年 8 月 13 日
Does anybody know how to vary the color of the scatter point and stem line in accordance to the Z-value for the 'stem3' plot function? Ideally the outcome of which would be similar to the purpose of 'C' for the 3D scatter plot: scatter3(X,Y,Z,S,C); where if C is a vector, its value is linearly mapped to the selected colormap. An example using the scatter3 function is:
V_dot_r = [0.027; 0.018; 0.018; 0.018; 0.0135];
V_dot_a = [2; 2; 1; 0.5; 0.5];
conv = [27, 33, 41, 50, 46];
scatter3(V_dot_r, V_dot_a, conv, 60, conv, 'filled')
colormap(cool)
colorbar
I would like to obtain a similar plot, however using the stem3 function rather than the scatter3 function. Is this possible?
Thanks in advance.

採用された回答

Star Strider
Star Strider 2018 年 8 月 12 日
This requires a bit more code than I would like, partially because it needs to scale the colors appropriately to match the scatter3 appearance. The loop appears to be necessary to plot all the colors correctly. It took a bit of experimenting to get this.
The Code
figure
cm = colormap(cool(max(conv)-min(conv)));
hold all
for k1 = 1:numel(conv)
sh(k1) = stem3(V_dot_r(k1), V_dot_a(k1), conv(k1));
cm_idx = max( conv(k1)-min(conv), 1 );
set(sh(k1), 'Color',cm(cm_idx,:), 'MarkerFaceColor',cm(cm_idx,:), 'MarkerEdgeColor',cm(cm_idx,:))
end
hold off
colorbar
grid on
view(-37.5, 30)
xlabel('V\_dot\_r')
ylabel('V\_dot\_a')
zlabel('conv')
The Plot
  13 件のコメント
Star Strider
Star Strider 2018 年 8 月 13 日
@Marco — Most likely. I don’t use caxis often, so it didn’t occur to me to experiment with it. I also wasn’t certain of the result you wanted, so I did the color scaling in my code.
A caxis call could eliminate the need for specific, coded, color-scaling of the sort I use here. (I’m running a long optimisation just now, so I can’t experiment with it.)
dpb
dpb 2018 年 8 月 13 日
"I used: caxis([min(conv) max(conv)])"
I've already professed "I know nuthink!" per Sgt. Schultz regarding caxis but I wonder if that shouldn't scale to
caxis(hAx.ZLim)
where hAx is the handle to the figure axes so the color map will max out at the scaling of the axes rather than the actual data point maximum which is somewhat less than the axis limits.

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2018 年 8 月 12 日
編集済み: dpb 2018 年 8 月 12 日
Doesn't look easy; there's no .CData property even using Yair's UNDOCUMENTED function to find any stem3 properties that weren't exposed by TMW.
Best I can come up with easily is an approximation --
hSt=stem3(V_dot_r, V_dot_a, conv, 'filled');
hold on
hSc=scatter3(V_dot_r, V_dot_a, conv, 60, conv, 'filled');
colormap(cool)
that will put the colors on the markers but leaves the stems in the default color -- you can change that to black, say, but not variable to match.
The alternative is to manually draw the lines for each marker after scatter.
Does seem to be a reasonable enhancement request, don't know why TMW wouldn't have included similar facility from git-go.
  4 件のコメント
Marco
Marco 2018 年 8 月 12 日
Cool, thanks for your help!
dpb
dpb 2018 年 8 月 12 日
See SS's better answer; the enhancement would be to incorporate the color vector top level interface similar to scatter3.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by