Multiple line Style on a yyaxis plot

5 次查看(过去 30 天)
I've plotted data from several tables in dat files on a yyaxis plot using:
S=["10D.dat","12D.dat","15D.dat","19D.dat","21D.dat","24D.dat","27D.dat","45D.dat","63D.dat","90D.dat","105D.dat"];
for k =1:numel(S)
T= readtable(S(k),"VariableNamingRule","preserve");
T = renamevars(T, ["Var1", "Var2", "Var3", "Var4"], ["Time","Ts","Rd", "Teff"])
yyaxis left
plot(T.Time, T.Rd)
yyaxis right
plot(T.Time, T.Ts)
hold on
end
grid on
yyaxis left
xlabel('Time [ms]')
ylabel('Droplet Radius [um]')
title('Pure Diesel')
yyaxis right
ylabel('Tempreture [K]')
However, My plot comes out like this:
But because there are so many data sets, some of the lines have markers in, making the plot difficult to read.
Is there a way of making all of the lines some varient of dashed?? I'm not bothered about colour.
And how can i get the legend to display just one set of 10-105??

回答(1 个)

Dev
Dev 2025-4-25
We can plot the lines as dashes using the LineStyle property available in the “plot” function in MATLAB. We can modify the plot function calls in the code provided above as follows-
plot(T.Time, T.Rd, 'LineStyle'); % Dashed
plot(T.Time, T.Ts, 'LineStyle');
We can also set different dash styles for each dataset to distinguish them by defining a list of line styles and looping through them, as shown below-
lineStyles = {'--', '-.', ':', '-', '--'}; % As many as datasets
Next, for showing only one set of legend, I am assuming that you want to show the legend for either only ‘Ts’ or only ‘Rd. We can achieve the same by collecting the legend handles for only one yyaxis and display the legend using “legend” function in MATLAB. Please refer the example code provided below for your reference-
legLabels = {'10D','12D','15D','19D','21D','24D','27D','45D','63D','90D','105D'};
legend(h, legLabels, 'Location', 'best') % Only Rd lines in legend
Kindly find all the relevant documentation links below-
I hope this resolves your query

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by