How can I use LineStyleOrder in Subplot?

2 views (last 30 days)
Pieter De Backer
Pieter De Backer on 22 Sep 2015
Answered: Govind KM on 1 Aug 2024
Hi all,
I am trying to plot subplots in which I have predefined my linestyleorder but I cannot get it to work. Can someone help me on this? It works fine for a normal plot in the way the code is constructed, but the looping and subplot are a level too high for my limited programming skills.
LineC1 = { '-' '-' '--' '--' '-' '--'};
LineC2 = { '-' '-' '--' '--' '-' '--'};
LineC3 = { '-' '-' '--' '--' '-' '--'};
LineC4 = { '-' '-' '--' '--' '-' '--'};
CaseData= [{C1Data}, {C2Data}, {C3Data}, {C4Data}];
% CaseHeader = [{C1Header}, {C2Header}, {C3Header}, {C4Header}];
CaseLine = [{LineC1}, {LineC2}, {LineC3}, {LineC4}];
figurehandle3 = figure('Name','Per Case Pressure and Volume Curves','Color',[1 1 1]);
for k = 1:4 %create handles for the subplots
h(k) = subplot(2,2,k);
end
for i = 1:4
subplot(h(i))
box(gca,'on'); %also tried without this line and with h(i) instead of gca
hold(gca,'all');
set(gca, 'LineStyleOrder', CaseLine{i})
plot(TimePoints,CaseData{i},'LineWidth',2);
title(['Case ' num2str(i)],'FontSize',14);
%set(legend(CaseHeader{i}), 'Location','northeastoutside', 'FontSize',11,...
'FontName','Agency FB','interpreter', 'tex');
% Create xlabel and ylabel
xlabel({'Time'},'FontSize',14);
ylabel({'Pressure / Volume'},'FontSize',14);
end
I have commented the legend out as I did not provide that data but plotting with the legend works perfect, I just cannot get the dashed lines where my array requires.
I have also tried without the handles and through playing with the hold feature without any succes...
Thank you in advance, Pieter
  1 Comment
Pieter De Backer
Pieter De Backer on 22 Sep 2015
Oh and this is C1Data:
C1Data =
1.0e+005 *
Columns 1 through 4
0 0 0.9969 1.7863
0.0000 0.0000 0.9969 1.7863
0.0000 0.0000 0.9969 1.7863
0.0000 0.0000 0.9969 1.7863
0.0000 0.0000 0.9969 1.7864
0.0000 0.0000 0.9970 1.7864
0.0000 0.0000 0.9970 1.7865
0.0000 0.0000 0.9970 1.7866
0.0000 0.0000 0.9970 1.7867
0.0000 0.0000 0.9970 1.7870
0.0000 0.0000 0.9971 1.7874
0.0000 0.0000 0.9971 1.7879
0.0000 0.0000 0.9972 1.7885
0.0000 0.0000 0.9973 1.7893
0.0000 0.0000 0.9975 1.7903
0.0000 0.0000 0.9977 1.7915
0.0000 0.0000 0.9979 1.7928
0.0000 0.0000 0.9982 1.7944
0.0000 0.0000 0.9985 1.7961
0.0000 0.0000 0.9989 1.7981
0.0000 0.0000 0.9993 1.8002
0.0000 0.0000 0.9998 1.8026
0.0000 0.0000 1.0003 1.8051
0.0000 0.0000 1.0009 1.8079
0.0000 0.0000 1.0016 1.8108
0.0000 0.0000 1.0023 1.8140
0.0000 0.0000 1.0030 1.8175
0.0000 0.0000 1.0038 1.8211
0.0000 0.0000 1.0046 1.8251
0.0000 0.0000 1.0055 1.8293
0.0000 0.0000 1.0065 1.8338
0.0000 0.0000 1.0074 1.8386
0.0000 0.0000 1.0085 1.8438
0.0000 0.0000 1.0096 1.8493
0.0000 0.0000 1.0107 1.8551
0.0000 0.0000 1.0119 1.8612
0.0000 0.0000 1.0131 1.8677
0.0000 0.0000 1.0144 1.8744
0.0000 0.0000 1.0157 1.8816
0.0000 0.0000 1.0171 1.8889
0.0000 0.0000 1.0185 1.8967
0.0000 0.0000 1.0200 1.9048
0.0000 0.0000 1.0214 1.9131
0.0000 0.0000 1.0229 1.9220
0.0000 0.0000 1.0245 1.9311
0.0000 0.0000 1.0260 1.9406
0.0000 0.0000 1.0276 1.9504
0.0000 0.0000 1.0292 1.9605
0.0000 0.0000 1.0309 1.9710
0.0000 0.0000 1.0326 1.9819
0.0000 0.0000 1.0343 1.9932
0.0000 0.0000 1.0361 2.0048
0.0000 0.0000 1.0379 2.0168
0.0000 0.0000 1.0399 2.0292
0.0000 0.0000 1.0419 2.0418
0.0000 0.0000 1.0439 2.0547
0.0000 0.0000 1.0460 2.0680
0.0000 0.0000 1.0482 2.0814
0.0000 0.0000 1.0503 2.0951
0.0000 0.0000 1.0526 2.1090
0.0000 0.0000 1.0548 2.1233
0.0000 0.0000 1.0571 2.1377
0.0000 0.0000 1.0594 2.1521
0.0000 0.0000 1.0617 2.1671
0.0000 0.0000 1.0640 2.1819
0.0000 0.0000 1.0663 2.1970
0.0000 0.0000 1.0686 2.2123
0.0000 0.0000 1.0709 2.2276
0.0000 0.0000 1.0732 2.2431
0.0000 0.0000 1.0755 2.2588
0.0000 0.0000 1.0779 2.2744
0.0000 0.0000 1.0802 2.2902
0.0000 0.0000 1.0826 2.3059
0.0000 0.0000 1.0850 2.3218
0.0000 0.0000 1.0875 2.3377
0.0000 0.0000 1.0899 2.3535
0.0000 0.0000 1.0924 2.3694
0.0000 0.0000 1.0949 2.3854
0.0000 0.0000 1.0974 2.4012
0.0000 0.0000 1.1000 2.4171
0.0000 0.0000 1.1025 2.4331
0.0000 0.0000 1.1051 2.4490
0.0000 0.0000 1.1076 2.4648
0.0000 0.0000 1.1102 2.4807
0.0000 0.0000 1.1128 2.4965
0.0000 0.0000 1.1154 2.5122
0.0000 0.0000 1.1180 2.5278
0.0000 0.0000 1.1206 2.5435
0.0000 0.0000 1.1232 2.5590
0.0000 0.0000 1.1258 2.5744
0.0000 0.0000 1.1283 2.5898
0.0000 0.0000 1.1308 2.6051
0.0000 0.0000 1.1333 2.6203
0.0000 0.0000 1.1358 2.6355
0.0000 0.0000 1.1383 2.6506
0.0000 0.0000 1.1407 2.6656
0.0000 0.0000 1.1431 2.6804
0.0000 0.0000 1.1456 2.6953
0.0000 0.0000 1.1480 2.7100
0.0000 0.0000 1.1504 2.7246
0.0000 0.0000 1.1528 2.7391
0.0000 0.0000 1.1553 2.7536
0.0000 0.0000 1.1578 2.7679
0.0000 0.0000 1.1602 2.7821
0.0000 0.0000 1.1626 2.7961
0.0000 0.0000 1.1650 2.8101
0.0000 0.0000 1.1674 2.8240
0.0000 0.0000 1.1697 2.8377
0.0000 0.0000 1.1719 2.8513
0.0000 0.0000 1.1741 2.8649
0.0000 0.0000 1.1763 2.8783
0.0000 0.0000 1.1784 2.8916
0.0000 0.0000 1.1805 2.9047
0.0000 0.0000 1.1825 2.9179
0.0000 0.0000 1.1845 2.9308
0.0000 0.0000 1.1865 2.9436
0.0000 0.0000 1.1885 2.9562
0.0000 0.0000 1.1904 2.9687
0.0000 0.0000 1.1924 2.9811
0.0000 0.0000 1.1943 2.9933
0.0000 0.0000 1.1962 3.0055
0.0000 0.0000 1.1980 3.0173
0.0000 0.0000 1.1998 3.0291
0.0000 0.0000 1.2016 3.0408
0.0000 0.0000 1.2034 3.0524
0.0000 0.0000 1.2051 3.0637
0.0000 0.0000 1.2067 3.0749
0.0000 0.0000 1.2084 3.0860
0.0000 0.0000 1.2100 3.0969
0.0000 0.0000 1.2117 3.1076
0.0000 0.0000 1.2133 3.1181
0.0000 0.0000 1.2148 3.1284
0.0000 0.0000 1.2164 3.1386
0.0000 0.0000 1.2179 3.1486
0.0000 0.0000 1.2193 3.1584
0.0000 0.0000 1.2208 3.1680
0.0000 0.0000 1.2222 3.1775
0.0000 0.0000 1.2236 3.1868
0.0000 0.0000 1.2250 3.1960
0.0000 0.0000 1.2263 3.2050
0.0000 0.0000 1.2277 3.2138
0.0000 0.0000 1.2290 3.2224
0.0000 0.0000 1.2303 3.2308
0.0000 0.0000 1.2315 3.2391
0.0000 0.0000 1.2327 3.2471
0.0000 0.0000 1.2338 3.2549
0.0000 0.0000 1.2350 3.2625
0.0000 0.0000 1.2361 3.2699
0.0000 0.0000 1.2372 3.2772
0.0000 0.0000 1.2383 3.2843
0.0000 0.0000 1.2393 3.2912
0.0000 0.0000 1.2403 3.2979
0.0000 0.0000 1.2412 3.3045
0.0000 0.0000 1.2420 3.3109
0.0000 0.0000 1.2427 3.3171
0.0000 0.0000 1.2434 3.3231
0.0000 0.0000 1.2442 3.3289
0.0000 0.0000 1.2448 3.3345
0.0000 0.0000 1.2455 3.3399
0.0000 0.0000 1.2463 3.3451
0.0000 0.0000 1.2470 3.3502
0.0000 0.0000 1.2476 3.3550
0.0000 0.0000 1.2483 3.3597
0.0000 0.0000 1.2489 3.3642
0.0000 0.0000 1.2495 3.3684
0.0000 0.0000 1.2501 3.3724
0.0000 0.0000 1.2506 3.3762
0.0000 0.0000 1.2511 3.3798
0.0000 0.0000 1.2515 3.3833
0.0000 0.0000 1.2519 3.3867
0.0000 0.0000 1.2523 3.3899
0.0000 0.0000 1.2527 3.3929
0.0000 0.0000 1.2530 3.3958
0.0000 0.0000 1.2534 3.3985
0.0000 0.0000 1.2538 3.4009
0.0000 0.0000 1.2542 3.4032
0.0000 0.0000 1.2546 3.4053
0.0000 0.0000 1.2550 3.4072
0.0000 0.0000 1.2554 3.4091
0.0000 0.0000 1.2557 3.4108
0.0000 0.0000 1.2559 3.4124
0.0000 0.0000 1.2561 3.4138
0.0000 0.0000 1.2563 3.4151
0.0000 0.0000 1.2564 3.4162
0.0000 0.0000 1.2566 3.4171
0.0000 0.0000 1.2567 3.4180
0.0000 0.0000 1.2567 3.4187
0.0000 0.0000 1.2568 3.4194
0.0000 0.0000 1.2568 3.4201
0.0000 0.0000 1.2568 3.4206
0.0000 0.0000 1.2568 3.4212
0.0000 0.0000 1.2569 3.4216
0.0000 0.0000 1.2569 3.4219
0.0000 0.0000 1.2569 3.4222
0.0000 0.0000 1.2570 3.4223
0.0000 0.0000 1.2570 3.4223
0.0000 0.0000 1.2570 3.4223
0.0000 0.0000 1.2569 3.4223
0.0000 0.0000 1.2569 3.4223
0.0000 0.0000 1.2568 3.4223
0.0000 0.0000 1.2567 3.4223
Columns 5 through 6
1.3072 0
1.3072 0.0000
1.3072 0.0000
1.3072 0.0000
1.3072 0.0000
1.3072 0.0000
1.3073 0.0000
1.3074 0.0000
1.3075 0.0000
1.3078 0.0000
1.3082 0.0000
1.3087 0.0000
1.3093 0.0000
1.3101 0.0000
1.3110 0.0000
1.3121 0.0000
1.3133 0.0000
1.3147 0.0000
1.3163 0.0000
1.3181 0.0000
1.3200 0.0000
1.3221 0.0000
1.3244 0.0000
1.3269 0.0000
1.3296 0.0000
1.3325 0.0000
1.3356 0.0000
1.3389 0.0000
1.3425 0.0000
1.3464 0.0000
1.3506 0.0000
1.3549 0.0000
1.3597 0.0000
1.3647 0.0000
1.3700 0.0000
1.3755 0.0000
1.3814 0.0000
1.3875 0.0000
1.3939 0.0000
1.4005 0.0000
1.4075 0.0000
1.4148 0.0000
1.4223 0.0000
1.4303 0.0000
1.4386 0.0000
1.4471 0.0000
1.4561 0.0000
1.4653 0.0000
1.4749 0.0000
1.4849 0.0000
1.4951 0.0000
1.5057 0.0000
1.5166 0.0000
1.5279 0.0000
1.5393 0.0000
1.5510 0.0000
1.5629 0.0000
1.5750 0.0000
1.5872 0.0000
1.5997 0.0000
1.6125 0.0000
1.6254 0.0000
1.6383 0.0000
1.6517 0.0000
1.6650 0.0000
1.6786 0.0000
1.6923 0.0000
1.7061 0.0000
1.7200 0.0000
1.7341 0.0000
1.7481 0.0000
1.7622 0.0000
1.7762 0.0000
1.7904 0.0000
1.8046 0.0000
1.8187 0.0000
1.8330 0.0000
1.8473 0.0000
1.8615 0.0000
1.8759 0.0000
1.8903 0.0000
1.9047 0.0000
1.9190 0.0000
1.9333 0.0000
1.9475 0.0000
1.9616 0.0000
1.9756 0.0000
1.9896 0.0000
2.0036 0.0000
2.0175 0.0000
2.0314 0.0000
2.0453 0.0000
2.0591 0.0000
2.0730 0.0000
2.0868 0.0000
2.1005 0.0000
2.1141 0.0000
2.1276 0.0000
2.1410 0.0000
2.1543 0.0000
2.1675 0.0000
2.1808 0.0000
2.1939 0.0000
2.2070 0.0000
2.2200 0.0000
2.2330 0.0000
2.2458 0.0000
2.2584 0.0000
2.2709 0.0000
2.2833 0.0000
2.2956 0.0000
2.3078 0.0000
2.3199 0.0000
2.3320 0.0000
2.3440 0.0000
2.3559 0.0000
2.3677 0.0000
2.3794 0.0000
2.3909 0.0000
2.4022 0.0000
2.4135 0.0000
2.4244 0.0000
2.4354 0.0000
2.4462 0.0000
2.4570 0.0000
2.4676 0.0000
2.4781 0.0000
2.4884 0.0000
2.4985 0.0000
2.5084 0.0000
2.5182 0.0000
2.5278 0.0000
2.5374 0.0000
2.5468 0.0000
2.5561 0.0000
2.5654 0.0000
2.5745 0.0000
2.5833 0.0000
2.5919 0.0000
2.6002 0.0000
2.6084 0.0000
2.6164 0.0000
2.6243 0.0000
2.6322 0.0000
2.6398 0.0000
2.6473 0.0000
2.6546 0.0000
2.6617 0.0000
2.6685 0.0000
2.6752 0.0000
2.6817 0.0000
2.6881 0.0000
2.6944 0.0000
2.7006 0.0000
2.7065 0.0000
2.7122 0.0000
2.7177 0.0000
2.7229 0.0000
2.7279 0.0000
2.7327 0.0000
2.7374 0.0000
2.7420 0.0000
2.7465 0.0000
2.7508 0.0000
2.7549 0.0000
2.7588 0.0000
2.7624 0.0000
2.7659 0.0000
2.7693 0.0000
2.7725 0.0000
2.7756 0.0000
2.7785 0.0000
2.7813 0.0000
2.7838 0.0000
2.7861 0.0000
2.7883 0.0000
2.7902 0.0000
2.7921 0.0000
2.7938 0.0000
2.7955 0.0000
2.7972 0.0000
2.7987 0.0000
2.8000 0.0000
2.8011 0.0000
2.8021 0.0000
2.8030 0.0000
2.8037 0.0000
2.8044 0.0000
2.8050 0.0000
2.8056 0.0000
2.8060 0.0000
2.8063 0.0000
2.8065 0.0000
2.8066 0.0000
2.8067 0.0000
2.8068 0.0000
2.8069 0.0000
2.8070 0.0000
2.8071 0.0000
2.8072 0.0000
2.8072 0.0000

Sign in to comment.

Answers (1)

Govind KM
Govind KM on 1 Aug 2024
Hi Pieter,
I believe you want your subplots of the data in the ‘CaseData’ array to have line styles corresponding to the ‘CaseLine’ array.
Since MATLAB R2023a, you can set this using the ‘LineStyleCyclingMethod’ property of the axes. By default, this is set to ‘aftercolor’, which cycles through the line styles set in ‘LineStyleOrder’ after cycling through the available colors in ‘ColorOrder’ (Seven predifined colors by default). As you are plotting six data columns in the same figure, the plots would cycle through the colors first, leading to six differently colored plots with the same line style. To change this, you can set the ‘LineStyleCyclingMethod’ property for each axis as required, to ‘withcolor’ to make it cycle along with the colors, or to ‘beforecolor’ to make it cycle before the colors.
for i = 1:4
subplot(h(i))
box(gca,'on');
hold(gca,'all');
set(gca, 'LineStyleOrder', CaseLine{i})
%Setting LineStyleCyclingMethod for the current subplot
set(gca,'LineStyleCyclingMethod','withcolor');
plot(TimePoints,CaseData{i},'LineWidth',2);
title(['Case ' num2str(i)],'FontSize',14);
% Create xlabel and ylabel
xlabel({'Time'},'FontSize',14);
ylabel({'Pressure / Volume'},'FontSize',14);
end
You can refer to the documentation of this property here:

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!