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일

2 개 추천

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

dpb
dpb 2018년 8월 12일
I thought it didn't look as though the face color property was an array...guess shoulda' tried, huh? :)
Star Strider
Star Strider 2018년 8월 12일
It’s actually a 3-element row vector. When I need to define elements of a colormap, I index the rows to define the different colors. Normally, that’s straightforward. Here, it’s first necessary to scale the range, then index into it. That took a bit of experimenting to figure out.
It shouldn’t be that difficult, anyway. If TMW can implement that in scatter3 and friends, why not also for stem3 and friends?
Maybe some day ... :)
dpb
dpb 2018년 8월 12일
Indeed, the lack of homogeneity between similar functions is really amazing; it's like each was given to an individual with no coordination or overall design ever happening.
I was speaking of the property being global to the entire handle object as opposed to being for each element/marker.
Indeed also I don't do a lot of in-depth messing with the color maps and all but it seems terribly complex and requires way too much in depth knowledge to use HG as implemented for a "high level rapid development" tool to make any change that isn't prepackaged.
While it's kinda' an entertaining challenge to figure out how to mung on the internals to create an effect, it can be a real time-consumer if one is actually trying to do something useful.
Star Strider
Star Strider 2018년 8월 12일
I could not possibly agree more!
Marco
Marco 2018년 8월 13일
편집: Marco 2018년 8월 13일
Thank you very much for that, that was very helpful. Yes, the inconsistency for manipulating similar functions is very frustrating indeed!
Hi Star Strider, I noticed that there is just one small issue with the above solution. You used:
cm = colormap(cool(max(conv)-min(conv)))
in order to scale the 'cool' colormap to the range of 'conv' values; i.e. from the original 64x3 colormap matrix to one in which the number of rows of the colormap is defined by the range of 'conv' (22 in this case).
However, as seen on the above plot, the colorbar varies from 0 to 1, and its color variation doesn't correlate to the values and colors portrayed on the stem plot. Is there a way around this with your proposed code?
Thanks
Marco
Marco 2018년 8월 13일
편집: Marco 2018년 8월 13일
I used:
caxis([min(conv) max(conv)])
That seemed to do the trick. But not sure if there is a better way of changing the properties of the colorbar so that when this function is called, it automatically correlates to the values and colors shown on the z-axis...
Star Strider
Star Strider 2018년 8월 13일
As always, my pleasure.
I forgot about the caxis call in my original Answer. (I was concentrating on getting the colours to plot correctly.) The colorbar correlation is something else TMW will need to add if it gets around to adding scaled colours to stem and stem3.
Just now starting my day here (UCT-6), not ignoring you.
dpb
dpb 2018년 8월 13일
편집: dpb 2018년 8월 13일
" not sure if there is a better way of changing the properties of the colorbar so that when this function is called, it automatically correlates to the values and colors shown on the z-axis."
I'm not sure whether one can use linkprop for that purpose or not to get automagic changes?
Marco
Marco 2018년 8월 13일
Hi Strider, no worries. So you think that caxis is currently the easiest way to correlate the colorbar to the values and colors portrayed on the z-axis?
Marco
Marco 2018년 8월 13일
Hi dpd, I'm not too sure about linkprop, but can look into it further. Thanks for the suggestion.
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.)
"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일

2 개 추천

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일
Thanks for your reply and thoughts on the matter. Yep, the approximation will do for now at least. Is there any way to bring this request/complaint to the attention of TMW for further inspection?
dpb
dpb 2018년 8월 12일
Sure, use the Contact Us link at top of page; then contact support link.
Attach link to this thread as supporting/background is probably simplest.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Labels and Styling에 대해 자세히 알아보기

태그

질문:

2018년 8월 12일

댓글:

dpb
2018년 8월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by