How to add Multiple reference lines in single MatLab plot
Mostra commenti meno recenti
Hello,
I have the plot I want, however I would like to add both vertical and horizontal lines to reference certain points within my graph. In the attachments is an image of what I am talking about. I would like to reference my average Impact energy, Avg, please see code below. As well as referencing the point when the temperature is equal to 70 C. If possible, I would also like to have the corresponding Impact Energy value (when Temp = 70 C) displayed. If you can help, great, thanks.
Beginning of code is as follows:
Temp = [100,75,50,25,0,-25,-50,-65,-75,-85,-100,-125,-150,-175];
Impact_Energy = [89.3,88.6,87.6,85.4,82.9,78.9,73.1,66,59.3,47.9,34.3,29.3,27.1,25];
% Part B
Avg = (89.3+25)/2; % This average is measured in Joules
plot(Temp,Impact_Energy,'r*')
title('Impact Energy V. Temperature')
xlabel('Temperature, measured in C')
ylabel('Impact Energy, measured in J')
set(gca, 'XLim', [-180, 200], 'XTick', -180:10:200,'XTickLabel', -180:10:200,'Fontsize',10);
hold on
scatter(Temp,Impact_Energy,'X')
line(Temp,Impact_Energy)
hold off
Risposta accettata
Più risposte (1)
KSSV
il 18 Apr 2018
Temp = [100,75,50,25,0,-25,-50,-65,-75,-85,-100,-125,-150,-175];
Impact_Energy = [89.3,88.6,87.6,85.4,82.9,78.9,73.1,66,59.3,47.9,34.3,29.3,27.1,25];
% Part B
Avg = (89.3+25)/2; % This average is measured in Joules
plot(Temp,Impact_Energy,'r*')
title('Impact Energy V. Temperature')
xlabel('Temperature, measured in C')
ylabel('Impact Energy, measured in J')
set(gca, 'XLim', [-180, 200], 'XTick', -180:10:200,'XTickLabel', -180:10:200,'Fontsize',10);
hold on
scatter(Temp,Impact_Energy,'X')
line(Temp,Impact_Energy)
% hold off
% DRaw line at x = 70
x = 70 ;
y = interp1(Temp,Impact_Energy,x) ;
plot([x,x],[y,0],'--r') plot([x,-180],[y,y],'--r')
YOu may follow the same for other line.
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!