How do I plot lines with different line widths?
1.326 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Leor Greenberger
am 22 Sep. 2011
Kommentiert: Walter Roberson
am 16 Feb. 2026 um 20:11
Hi, I want to do: plot(x1,y1,x2,y2,'LineWidth',8) but the linewidth propery ends up applying to both lines. Do I have to use two plot functions with a hold on command to have line1 a different width than line2? Thanks.
3 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 29 Aug. 2023
Bearbeitet: MathWorks Support Team
am 13 Nov. 2024
To plot two lines with different line widths, you can use either of these approaches. 1. Return the two “Line” objects as an output argument from the “plot” function and then set the “LineWidth” property for each. p = plot(x1,y1,x2,y2) p(1).LineWidth = 5; p(2).LineWidth = 10; 2. Use the “hold on” command to plot the two lines separately. Specify the line width by setting the “LineWidth” property a name-value pair. plot(x1,y1,'LineWidth',5) hold on plot(x2,y2,'LineWidth',10) hold off
2 Kommentare
Mike Garrity
am 8 Mär. 2016
Just FYI, there is an "official" syntax for setting a property to different values on different objects. However, it's really ugly, and doesn't work everywhere. For example, I don't think that the plot function accepts this form.
It looks like this:
h = plot(x1,y1,x2,y2);
set(h,{'LineWidth'},{5;10})
The property name and property value need to each be a cell array, and the shape of the value cell array has to match the shape of the handle cell array.
That said, you're really better off with 2 calls to set in this case.
Weitere Antworten (4)
Wayne King
am 22 Sep. 2011
Hi: You can use handles.
h = plot(x1,y1,x2,y2);
set(h(1),'linewidth',1);
set(h(2),'linewidth',2);
0 Kommentare
Hari Desanur
am 15 Nov. 2016
Bearbeitet: Hari Desanur
am 15 Nov. 2016
The line width for a particular line can be set using line object handles. For example -
l = plot(x1,y1,x2,y2);
l(1).LineWidth = 3; % set line width of 3 for the first line (x1,y1)
l(2).LineWidth = 6;
0 Kommentare
SHAILENDRA PANDEY
am 11 Okt. 2020
x = 1:.01:10;
y1 = sin(x);
y2 = cos(x);
p = plot(x,y1,x,y2)
set(p,{'LineWidth'},{5;10})
Line width, specified as a positive value in points, where 1 point = 1/72 of an inch. If the line has markers, then the line width also affects the marker edges.
The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.
0 Kommentare
Auwalu
am 16 Feb. 2026 um 13:25
Bearbeitet: Walter Roberson
am 16 Feb. 2026 um 20:09
%% Auwal 2026 Research Model - Analytical Solutions
% Extended Raptis (1982) with Soret and Dufour Effects
% Vertical channel flow with double-diffusive convection
clear all; close all; clc;
%% Parameters (User can modify these)
lambda = 1; % Flow parameter
Pr = 0.71; % Prandtl number (air: 0.71, water: 7)
Sc = 0.6; % Schmidt number
e = 1; % Rotation/MHD parameter
Gr = 100; % Thermal Grashof number
Gm = 50; % Solutal Grashof number
A = 1; % Thermal BC parameter at z=0
B = 1; % Thermal BC parameter at z=0
gamma = 1; % Temperature gradient parameter
H = 1; % Channel height
Sr = 0.1; % Soret number (small)
Df = 0.1; % Dufour number (small)
epsilon = 1; % Perturbation parameter (Sr = ε*S1, Df = ε*D1)
S1 = Sr/epsilon; % Scaled Soret coefficient
D1 = Df/epsilon; % Scaled Dufour coefficient
% Spatial grid
Nz = 100;
z = linspace(0, H, Nz)';
%% BASE SOLUTIONS (Zeroth Order - Raptis 1982)
fprintf('Computing base solutions (Raptis 1982)...\n');
% Temperature base solution
Delta = B*(1 - exp(-lambda*Pr*H)) - A*lambda*Pr;
a0 = -gamma*exp(-lambda*Pr*H)/Delta;
a1 = gamma/Delta;
theta0 = a0 + a1*exp(-lambda*Pr*z);
% Concentration base solution
b0 = -exp(-lambda*Sc*H)/(1 - exp(-lambda*Sc*H));
b1 = 1/(1 - exp(-lambda*Sc*H));
C0 = b0 + b1*exp(-lambda*Sc*z);
% Velocity base solution
% Characteristic roots for homogeneous solution
m1 = (-lambda + sqrt(lambda^2 + 8i*e))/2;
m2 = (-lambda - sqrt(lambda^2 + 8i*e))/2;
% Particular solution coefficients for Q0
P0 = (Gr*a0 + Gm*b0)/(2i*e);
P1 = -Gr*a1/(lambda^2*Pr*(Pr-1) - 2i*e);
P2 = -Gm*b1/(lambda^2*Sc*(Sc-1) - 2i*e);
% Boundary conditions for Q0
Q0_at_0 = P0 + P1 + P2;
Q0_at_H = P0 + P1*exp(-lambda*Pr*H) + P2*exp(-lambda*Sc*H);
% Solve for homogeneous coefficients G1, G2
A_mat = [1, 1; exp(m1*H), exp(m2*H)];
b_vec = [-Q0_at_0; -Q0_at_H];
G_coeff = A_mat\b_vec;
G1 = G_coeff(1);
G2 = G_coeff(2);
% Complete Q0 solution
Q0 = G1*exp(m1*z) + G2*exp(m2*z) + P0 + P1*exp(-lambda*Pr*z) + P2*exp(-lambda*Sc*z);
%% FIRST-ORDER CORRECTIONS (Soret & Dufour Effects)
fprintf('Computing first-order corrections (Soret & Dufour)...\n');
% Check for resonance case (Pr = Sc)
if abs(Pr - Sc) < 1e-10
fprintf('Warning: Pr = Sc (resonance case). Using resonant solution.\n');
% Resonant temperature correction (Pr = Sc)
P_res = -D1*lambda*Pr*b1;
% Solve for K1, K2 from BCs
A_mat_theta = [B, B - A*lambda*Pr; ...
1, exp(-lambda*Pr*H)];
b_vec_theta = [A*lambda*Pr*P_res; -P_res*H*exp(-lambda*Pr*H)];
K_coeff = A_mat_theta\b_vec_theta;
K1 = K_coeff(1);
K2 = K_coeff(2);
theta1 = K1 + K2*exp(-lambda*Pr*z) + P_res*z.*exp(-lambda*Pr*z);
% Resonant concentration correction (Pr = Sc)
Q_res = S1*lambda*Pr*a1;
% Solve for L1, L2 from BCs
A_mat_C = [1, 1; 1, exp(-lambda*Pr*H)];
b_vec_C = [Q_res*0; -Q_res*H*exp(-lambda*Pr*H)];
L_coeff = A_mat_C\b_vec_C;
L1 = L_coeff(1);
L2 = L_coeff(2);
C1 = L1 + L2*exp(-lambda*Pr*z) + Q_res*z.*exp(-lambda*Pr*z);
else
% Non-resonant case (Pr ≠ Sc)
% Temperature correction coefficients
M = D1*Sc*b1/(Sc - Pr);
Delta_C = B*(1 - exp(-lambda*Sc*H)) - A*lambda*Sc;
K2 = -M*Delta_C/Delta;
K1 = M*(Delta_C*exp(-lambda*Pr*H)/Delta - exp(-lambda*Sc*H));
theta1 = K1 + K2*exp(-lambda*Pr*z) + M*exp(-lambda*Sc*z);
% Concentration correction coefficients
N = -S1*Pr*a1/(Sc - Pr);
L2 = -N*(1 - exp(-lambda*Pr*H))/(1 - exp(-lambda*Sc*H));
L1 = N*(exp(-lambda*Sc*H) - exp(-lambda*Pr*H))/(1 - exp(-lambda*Sc*H));
C1 = L1 + L2*exp(-lambda*Sc*z) + N*exp(-lambda*Pr*z);
end
% Velocity correction
R0 = (Gr*K1 + Gm*L1)/(2i*e);
R1 = (-Gr*K2 - Gm*N)/(lambda^2*Pr*(Pr-1) - 2i*e);
R2 = (-Gr*M - Gm*L2)/(lambda^2*Sc*(Sc-1) - 2i*e);
% Boundary conditions for Q1
Q1_at_0 = R0 + R1 + R2;
Q1_at_H = R0 + R1*exp(-lambda*Pr*H) + R2*exp(-lambda*Sc*H);
% Solve for homogeneous coefficients H1, H2
H_coeff = A_mat\[-Q1_at_0; -Q1_at_H];
H1 = H_coeff(1);
H2 = H_coeff(2);
% Complete Q1 solution
Q1 = H1*exp(m1*z) + H2*exp(m2*z) + R0 + R1*exp(-lambda*Pr*z) + R2*exp(-lambda*Sc*z);
%% COMPLETE SOLUTIONS (to first order)
fprintf('Assembling complete solutions...\n');
theta = theta0 + epsilon*theta1;
C = C0 + epsilon*C1;
Q = Q0 + epsilon*Q1;
% Extract real and imaginary parts of velocity
U = real(Q); % Velocity component in x-direction
V = imag(Q); % Velocity component in y-direction
%% PLOTTING RESULTS
fprintf('Generating plots...\n');
figure('Position', [100, 100, 1200, 800]);
% Temperature profile
subplot(2, 3, 1);
plot(theta, z, 'b-', 'LineWidth', 2);
hold on;
plot(theta0, z, 'r--', 'LineWidth', 1.5);
xlabel('\theta(z)', 'FontSize', 12);
ylabel('z', 'FontSize', 12);
title('Temperature Profile', 'FontSize', 14);
legend('With Soret/Dufour', 'Base (Raptis 1982)', 'Location', 'best');
grid on;
% Concentration profile
subplot(2, 3, 2);
plot(C, z, 'b-', 'LineWidth', 2);
hold on;
plot(C0, z, 'r--', 'LineWidth', 1.5);
xlabel('C(z)', 'FontSize', 12);
ylabel('z', 'FontSize', 12);
title('Concentration Profile', 'FontSize', 14);
legend('With Soret/Dufour', 'Base (Raptis 1982)', 'Location', 'best');
grid on;
% Velocity magnitude
subplot(2, 3, 3);
plot(abs(Q), z, 'b-', 'LineWidth', 2);
hold on;
plot(abs(Q0), z, 'r--', 'LineWidth', 1.5);
xlabel('|Q(z)|', 'FontSize', 12);
ylabel('z', 'FontSize', 12);
title('Velocity Magnitude', 'FontSize', 14);
legend('With Soret/Dufour', 'Base (Raptis 1982)', 'Location', 'best');
grid on;
% Velocity components
subplot(2, 3, 4);
plot(U, z, 'b-', 'LineWidth', 2);
hold on;
plot(V, z, 'r-', 'LineWidth', 2);
xlabel('Velocity Components', 'FontSize', 12);
ylabel('z', 'FontSize', 12);
title('Velocity Components', 'FontSize', 14);
legend('U (real part)', 'V (imaginary part)', 'Location', 'best');
grid on;
% Cross-diffusion effects
subplot(2, 3, 5);
plot(epsilon*theta1, z, 'g-', 'LineWidth', 2);
hold on;
plot(epsilon*C1, z, 'm-', 'LineWidth', 2);
xlabel('Correction Magnitude', 'FontSize', 12);
ylabel('z', 'FontSize', 12);
title('Cross-Diffusion Corrections', 'FontSize', 14);
legend('Dufour effect on \theta', 'Soret effect on C', 'Location', 'best');
grid on;
% Velocity vector plot in channel
subplot(2, 3, 6);
% Create mesh for vector plot
z_vec = linspace(0, H, 20);
x_vec = linspace(-0.5, 0.5, 20);
[X, Z] = meshgrid(x_vec, z_vec);
% Interpolate velocity components
U_interp = interp1(z, U, Z, 'spline');
V_interp = interp1(z, V, Z, 'spline') * 0.1; % Scale for visualization
quiver(X, Z, U_interp, V_interp, 1.5, 'b', 'LineWidth', 1);
xlabel('x (cross-channel)', 'FontSize', 12);
ylabel('z (vertical)', 'FontSize', 12);
title('Velocity Field in Channel', 'FontSize', 14);
axis equal tight;
grid on;
sgtitle('Auwal 2026: Extended Raptis Model with Soret & Dufour Effects', ...
'FontSize', 16, 'FontWeight', 'bold');
%% OUTPUT SUMMARY
fprintf('\n=== SOLUTION SUMMARY ===\n');
fprintf('Parameters:\n');
fprintf(' λ = %.2f, Pr = %.2f, Sc = %.2f\n', lambda, Pr, Sc);
fprintf(' Gr = %.2f, Gm = %.2f, e = %.2f\n', Gr, Gm, e);
fprintf(' Sr = %.3f, Df = %.3f, ε = %.2f\n', Sr, Df, epsilon);
fprintf(' Channel height H = %.2f\n', H);
fprintf('\nSolution Characteristics:\n');
fprintf(' Max temperature: θ_max = %.4f at z = %.3f\n', max(theta), z(find(theta==max(theta),1)));
fprintf(' Max concentration: C_max = %.4f at z = %.3f\n', max(C), z(find(C==max(C),1)));
fprintf(' Max velocity: |Q|_max = %.4f at z = %.3f\n', max(abs(Q)), z(find(abs(Q)==max(abs(Q)),1)));
fprintf(' Cross-diffusion effects:\n');
fprintf(' Dufour correction: max = %.4f, RMS = %.4f\n', max(abs(epsilon*theta1)), rms(epsilon*theta1));
fprintf(' Soret correction: max = %.4f, RMS = %.4f\n', max(abs(epsilon*C1)), rms(epsilon*C1));
%% SAVING RESULTS
save('auwal_2026_results.mat', 'z', 'theta', 'C', 'Q', 'U', 'V', ...
'theta0', 'C0', 'Q0', 'theta1', 'C1', 'Q1', ...
'lambda', 'Pr', 'Sc', 'Gr', 'Gm', 'e', 'Sr', 'Df', 'epsilon');
%% FUNCTION FOR PARAMETER SENSITIVITY ANALYSIS (Optional)
function analyze_parameter_sensitivity()
% This function can be used to study the effect of different parameters
% Uncomment and modify as needed
% Example: Study effect of Sr and Df
Sr_range = linspace(0, 0.2, 10);
Df_range = linspace(0, 0.2, 10);
[Sr_grid, Df_grid] = meshgrid(Sr_range, Df_range);
Q_max = zeros(size(Sr_grid));
for i = 1:numel(Sr_grid)
% Recompute with different Sr, Df
% (You would need to modify the main code to accept parameters)
% Q_max(i) = max_velocity_for_parameters(Sr_grid(i), Df_grid(i));
end
% Plot sensitivity
figure;
contourf(Sr_grid, Df_grid, Q_max, 20);
colorbar;
xlabel('Soret number Sr');
ylabel('Dufour number Df');
title('Maximum Velocity vs. Cross-Diffusion Parameters');
end
1 Kommentar
Walter Roberson
am 16 Feb. 2026 um 20:11
This is certainly not a minimal working example.
It is not clear to me that the difference between line width 1, line width 1.5, and line width 2 will be obvious to viewers here in MATLAB Answers.
Siehe auch
Kategorien
Mehr zu Labels and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
