How to plot line on surface object

1 visualización (últimos 30 días)
Gianluca Finotti
Gianluca Finotti el 13 de Mzo. de 2018
Comentada: Gianluca Finotti el 20 de Mzo. de 2018
Hi, I made a plot by using a tutorial found on youtube (see figure)
I need to add a vertical line.
This is the code:
h = findobj('type','figure');
n = length(h);
dataToPlot = mediaInfraCondRev;
plotHeatMap
The last line (plotHeatMap) opens this code:
f = figure(n+1);
%Inizialize plotting vectors
buf_len = 1895; % about 30 seconds of data
%index = 1:buf_len; % riga originale trovata su internet
index = time.minsTot(:,1)'; % riga modificata per plottare minuti su asse x
zeroIndex = zeros(size(index));
tcdata = zeroIndex; % rolling vector of temperature readings length buf_len
limits = [min(dataToPlot) max(dataToPlot+0.05)]; %expected range of temps for plotting and color scaling
%set the axes limits and select a 2D (x,z) view (this prevents
%autoscaling
% myAxes = axes ('xLim', [0 buf_len], 'YLim', [0 0.1], 'Zlim', limits,
% 'CLim', limits); % questa e' la riga originale trovata su youtube
myAxes = axes ('xLim', [0 max(index)], 'YLim', [0 0.1], 'Zlim', limits, 'CLim', limits); % questa e' la riga modificata per plottare i minuti su asse x
view(0,0);
grid on;
% Create surface graphics object s to display temperature data in (x,z)
% plane, area color based on temperature readings
% X e Y definiscono le coordinate sul rettangolo. Z definisce la
% superficie sulla griglia e la colora in base a C
% 'XData' 'YData' 'ZData' 'CData'
s = surface (index, [0, 0], [tcdata; zeroIndex], [tcdata; tcdata]);
% Set surface face and edges to fill with CData values, add labels
set(s, 'EdgeColor', 'flat', 'FaceColor', 'flat', 'Parent', myAxes)
% parent 'myAxes' dice di mettere il surface object all'interno degli assi
colorbar
title('Temperature Readings, \circC')
xlabel('Time (minutes)')
zlabel('Temperature(\circC)')
set(f, 'Position', [200 200 890 660])
drawnow;
% INSERIAMO I DATI
tcdata = dataToPlot';
%update plot data and corresponding color
set(s, 'Zdata', [tcdata; zeroIndex], 'Cdata', [tcdata; tcdata])
%force MATLAB to redraw the figure
drawnow;
Everything looks perfect, except for one thing: I need to add a vertical line on minute 3 and minute 23. I tried with:
line([3 3], get(gca, 'ylim'));
This line kind of works on a normal plot (see example)
But it does not show anything if I try on this plot and I can't figure out what to do. Any suggestion?
Thank you for your time, Gluce
  1 comentario
Gianluca Finotti
Gianluca Finotti el 13 de Mzo. de 2018
P.S. there are some comments in the code that do not apply anymore. The original code was made for a sliding plot: that is, plotting online while collecting data. I slightly adapted it to plot the entire length of data at the end of the experiment.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 13 de Mzo. de 2018
‘Any suggestion?’
Experiment with plot3 instead of plot to plot a line on a 3D plot.
Example
[x,y] = meshgrid(-2:0.2:2);
z = x .* exp(-x.^2 - y.^2);
surf(x,y,z)
hold on
plot3(x(10,:), ones(size(x(:,10)))*y(10,1), z(10,:), '--r', 'LineWidth',3)
hold off
grid on
shading interp
Experiment with your plot to get the result you want.
  3 comentarios
Star Strider
Star Strider el 20 de Mzo. de 2018
As always, my pleasure!
Gianluca Finotti
Gianluca Finotti el 20 de Mzo. de 2018
=)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by