Scatter plots and lines
I am wanting to add in a line like the graph below, but cannot seem to get the black line to stop going upwards. The gradient of the line is 4, please see my code and help!
clearvars;
close all;
clc;
% Extracted data
L = [0.2, 0.21, 0.22, 0.23, 0.24, 0.25]; % Length in µm
G = [0.002073593, 0.002034555, 0.00198774, 0.00194322, 0.00191650, 0.00188695]; % G in µm⁻¹
V = [33.4790, 35.0453, 35.5131, 35.7370, 36.2533, 36.3155]; % V in µm/s
% Plotting
figure;
hold on;
% Plot G vs V as a regular line plot
plot(V, G, ‘o’, ‘LineWidth’, 2, ‘Color’, ‘b’, ‘MarkerFaceColor’, ‘b’, ‘DisplayName’, ‘Data’);
% Add a black line with gradient = 4 starting from the origin
m = 4; % Gradient
V_line = linspace(0, max(V)+1, 100); % Start from 0
G_line = m * V_line;
plot(V_line, G_line, ‘k-‘, ‘LineWidth’, 2, ‘DisplayName’, ‘Gradient = 4 (from origin)’);
% Formatting the plot
xlabel(‘Velocity V (µm/s)’, ‘FontSize’, 30);
ylabel(‘Thermal Gradient G (µm⁻¹)’, ‘FontSize’, 30);
title(‘G vs V for Varying Separation Distances’, ‘FontSize’, 35);
legend(‘Location’, ‘northeast’, ‘FontSize’, 20);
grid on;
xlim([min(0, min(V)-0.5), max(V)+0.5]);
ylim([min(0, min(G)-0.00001), max(G)+0.00001]);I am wanting to add in a line like the graph below, but cannot seem to get the black line to stop going upwards. The gradient of the line is 4, please see my code and help!
clearvars;
close all;
clc;
% Extracted data
L = [0.2, 0.21, 0.22, 0.23, 0.24, 0.25]; % Length in µm
G = [0.002073593, 0.002034555, 0.00198774, 0.00194322, 0.00191650, 0.00188695]; % G in µm⁻¹
V = [33.4790, 35.0453, 35.5131, 35.7370, 36.2533, 36.3155]; % V in µm/s
% Plotting
figure;
hold on;
% Plot G vs V as a regular line plot
plot(V, G, ‘o’, ‘LineWidth’, 2, ‘Color’, ‘b’, ‘MarkerFaceColor’, ‘b’, ‘DisplayName’, ‘Data’);
% Add a black line with gradient = 4 starting from the origin
m = 4; % Gradient
V_line = linspace(0, max(V)+1, 100); % Start from 0
G_line = m * V_line;
plot(V_line, G_line, ‘k-‘, ‘LineWidth’, 2, ‘DisplayName’, ‘Gradient = 4 (from origin)’);
% Formatting the plot
xlabel(‘Velocity V (µm/s)’, ‘FontSize’, 30);
ylabel(‘Thermal Gradient G (µm⁻¹)’, ‘FontSize’, 30);
title(‘G vs V for Varying Separation Distances’, ‘FontSize’, 35);
legend(‘Location’, ‘northeast’, ‘FontSize’, 20);
grid on;
xlim([min(0, min(V)-0.5), max(V)+0.5]);
ylim([min(0, min(G)-0.00001), max(G)+0.00001]); I am wanting to add in a line like the graph below, but cannot seem to get the black line to stop going upwards. The gradient of the line is 4, please see my code and help!
clearvars;
close all;
clc;
% Extracted data
L = [0.2, 0.21, 0.22, 0.23, 0.24, 0.25]; % Length in µm
G = [0.002073593, 0.002034555, 0.00198774, 0.00194322, 0.00191650, 0.00188695]; % G in µm⁻¹
V = [33.4790, 35.0453, 35.5131, 35.7370, 36.2533, 36.3155]; % V in µm/s
% Plotting
figure;
hold on;
% Plot G vs V as a regular line plot
plot(V, G, ‘o’, ‘LineWidth’, 2, ‘Color’, ‘b’, ‘MarkerFaceColor’, ‘b’, ‘DisplayName’, ‘Data’);
% Add a black line with gradient = 4 starting from the origin
m = 4; % Gradient
V_line = linspace(0, max(V)+1, 100); % Start from 0
G_line = m * V_line;
plot(V_line, G_line, ‘k-‘, ‘LineWidth’, 2, ‘DisplayName’, ‘Gradient = 4 (from origin)’);
% Formatting the plot
xlabel(‘Velocity V (µm/s)’, ‘FontSize’, 30);
ylabel(‘Thermal Gradient G (µm⁻¹)’, ‘FontSize’, 30);
title(‘G vs V for Varying Separation Distances’, ‘FontSize’, 35);
legend(‘Location’, ‘northeast’, ‘FontSize’, 20);
grid on;
xlim([min(0, min(V)-0.5), max(V)+0.5]);
ylim([min(0, min(G)-0.00001), max(G)+0.00001]); scatter, line, plot MATLAB Answers — New Questions