MATLAB Answers

Fill under lines in plot3

41 views (last 30 days)
Meva
Meva on 22 Mar 2017
Edited: Meva on 23 Mar 2017
Hello,
I need to fill under the Z-data in a plot3. I have below function.
function mmplot3(x,y,z,c,w,b,d)
%MMPLOT3 3-D color-based plot.
% MMPLOT3(X,Y,Z,C,W,B) or MMPLOT3(X,Y,Z,C,W,B,D), where X, Y, Z and C are
% 4 vectors of the same length, plots a line in 3-space through the points
% whose coordinates are the elements of X, Y and Z with colors
defined by
% vector C. W is the width of the line, B is the line brightness while
% solid line plot is used, otherwise it's the marker style and D is the
% indices increment.
x = x(:); y = y(:); z = z(:); c = c(:);
switch b
case {'.','o','x','+','*','s','d','v','^','<','>','p','h'}
iNaN=find(isnan(x));
if isempty(iNaN), iNaN = length(x); end
i = [1:d:iNaN(1),iNaN(1)];
x = x(i); y = y(i); z = z(i); c = c(i);
scatter3(x,y,z,w,c,b)
otherwise
plot3(x,y,z,'linestyle','none') % make a blank plot
surface([x, x], [y, y], [z, z], ...
[c, c], 'EdgeColor','flat', 'FaceColor','none', 'linewidth',w, 'EdgeAlpha',b)
end
Please see attached. The 3d plot I have (on the right hand side attached) is quite is unclear, not like the figure on left hand side.
I need to fill under the Z data with white color.
Also associate each Z-data with each time (X-data) in the plot.

  4 Comments

Show 1 older comment
Meva
Meva on 23 Mar 2017
Thanks for the suggestion. I used :
vert = [x0 0 z(1,1); x0 0 -0.6; x0 1 -0.6; x0 1 z(1,nc)];
fac = [1 2 3 4]
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',white(1),'FaceColor','flat')
This however produces a triangle and my z data has smooth shape. So, I guess I need to use something else.
The code I attached here does produce a 3d plot which is the answer to my previous question.
KSSV
KSSV on 23 Mar 2017
You have not mentioned inputs....x,y,z
Meva
Meva on 23 Mar 2017
Thanks KSSV. Please see attached file. On the left hand side there is a clear figure which is I would like to obtain. The figure on the right hand side is what I have obtained. Please ignore the difference between data. I just would like to have the same appearance.
The above code is a nested function. The main m file has
figure(1)
colormap hsv
for kt = 1 : tstep : nr
mmplot3(t(kt,:), x2(kt,:), p(kt,:), p(kt,:), 1, 0.5)
hold on
end
%%%%following part is to fill but it does not work!
vert = [t0 0 p(1,1);t0 0 -0.6;t0 1 -0.6;t0 1 p(1,nc)];
fac = [1 2 3 4]
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',white(1),'FaceColor','flat')
So, in the main code these are
t1 = t0 : dt : tfinal;
x1 = x0 : dx : xfinal;
[x2,t]=meshgrid(x1,t1);
[nr,nc]=size(x2);
p = zeros(nr,nc);
where
t0=0.1;
tfinal = 1;
dt = 0.0001; % step size
x0 = 0;
xfinal = 1;
dx = 0.001; % step size
% tstep = 9900; % time step for 3D plot
tstep=900;

Sign in to comment.

Answers (0)

Sign in to answer this question.


Translated by