Making 3D stem-plots with x-axis as baseline?

Viewed 161

I want to make 3D stemplots where the stems originate from a line (the x-axis in my case) in matlab. (Beautiful paint illustration below.)

enter image description here

Matlab has a function for 3D-stem-plots (stem3), but it uses the xy-plane as baseline. stem3-objects has a property called Baseline, with the default value Baseplane, but I don't now how to modify it (or if its possible). Any suggestions on how to solve this problem? One solution is to create a new line for each data-point, but is there a better way?

1 Answers

There is no better way, I would assume.

But creating it manually seems simple enough:

x = linspace(0,2*pi,10);
y = sin(x);
z = ones(10,1);

h = scatter3(x,y,z); hold on
for ii = 1:numel(x)
    plot3( [x(ii),x(ii)], [0,y(ii)], [0,z(ii)],...
           'color', h.CData,...         % same color as the markers
           'linewidth', h.LineWidth,... % same line width as the markers
           'HandleVisibility', 'off')   % the stems won't show up in legend
end

enter image description here

Related