# best tool for plotting 3 3D lines in one plot

I'm trying to recreate an image using either R, Matlab or Python (the languages I know) but I'm having troubles finding a good library for the task. The image I'd like to recreate is the one below. The important parts are the signals, dynamic bands and the "walls". Any advise is welcome.

I've played around a bit with scatterplot3d in R and I'm not sure how or if I'll be able to get anything similar. I've looked a bit at matplotlib for Python but I'm not so familiar with it so far.

I'm awaiting your expert opinions :)

I've spent the last hour writing up the rudimentary basics of what you would like to do in Matlab, with the caveat that the bands are not going to be 3D tubes but are rather filled polygons.

![%% This script shows how to plot multiple 3D lines with envelopes as well as planar walls

% Let's first generate some data which will be stationary with noise.
clear all;
hold on;
numPoints = 50;

% create 4 data vectors. We will use the z-axis just to separate the
% different data series. The y-axis will be their amplitude, and x-axis
% will be the time.
for i = 1:4
x(:,i) = 1:numPoints;
y(:,i) = rand(numPoints,1);

% we add in this 2*i offset so that the plots are well separated in the
% 3D space.
z(:,i) = ones(numPoints,1)*(5*i);

end

% create polygon vertices (for envelope/band) and plot them with patch
for i = 1:4
X = $x(:,i);flipud(x(:,i))$;        % we use flipud to flip the x array backwards because we need the vertices to be listed in order that they should be connected
Y = $y(:,i)+.5; flipud(y(:,i)-.5)$; % the +.5 adjustment is to simply make the band envelope far away from the data
Z = $z(:,i);flipud(z(:,i))$;        %
patch(X,Y,Z,'b');                   % creates polygon and fills it
alpha(0.3);                         % changes transparency of band
end

% fill vertices which are oriented to form a rectangle in 3D space
% I've chosen the vertices just so that the 'wall' is outside all the z
% values(0-20) and outside all the y-values (-0.5 to 1.5). FaceAlpha
% controls transparency.
fill3($30 30 30 30$, $-1 -1 2 2$,$-1 21 21 -1$,'g','FaceAlpha',0.1);
fill3($45 45 45 45$, $-1 -1 2 2$,$-1 21 21 -1$,'g','FaceAlpha',0.1);

% plot all the data vectors
plot3(x,y,z,'LineWidth',2)

% makes all the axes proportional to one another, which is a must when
% fiddling with settings for view angles, etc.
axis equal

% this stuff I got by creating a view angle that I liked, then using the
% 'generate code' option in the Matlab figure window to grab the camera
% angle, target and position.
set(gca,'PlotBoxAspectRatio',$434 342.3 8557.5$,...
'DataAspectRatio',$1 1 1$,...
'CameraViewAngle',9.09602339047084,...
'CameraTarget',$27.5247058760224 0.500000000000018 13.1366020433877$,...
'CameraPosition',$-18.5114941239776 -82.6053 113.849302043388$);

set(gcf,'Color',$1 1 1$);][1]


This should give you the plot below. The angle is changed and it is missing the gridlines, but it has the key elements of your plot. If you want to go for an exact reproduction, you're going to need to use the streamtubes functionality in Matlab (if it's even possible). Otherwise, if you add another lightly shaded polygon for the green background and add some gray lines for the axes ticks, you can come reasonably close to the original.

• This meets what I was trying to achieve, thank you. My last try was using ggplot2 with heavy style editing and then some Photoshop on top. A 3D version of ggplot2 would be nice, in my opinion Matlab does not produce the prettiest plots :) Commented Jul 14, 2015 at 15:48

Consider dropping your 3-D requirement and you'll have lots more tool options and a more readable chart. That is, the 3-D perspective add extra work for the reader and greater chance for misreading. Consider using separate panels for each sensor, for instance. I think ggplot2 calls them facets.

Here's a mock-up I made with my own tool, JMP. In whatever tool you use, you'll probably have to define the bands before making the graph. In my case, I've used an area range as the graphic representation of the band.

• Thank you Xan for your input. This was my first idea since in my opinion is a better way of showing the same information. Although it's not purely my decision and a 3D version was wished for :/. I think using ggplot2 and facets could yield something looking kind of 3Dish by changing the background colors, better to have something than nothing. Commented Jul 7, 2015 at 6:52