Parts of a subplot are missing after add next subplot

Hello,

(using 2024.0.0 on Windows 11)

I want to plot a number of plots in one graphic window. I used subplot for this. Furthermore I want a funktion that only give you one plot, but you can add annother one to the same graphic window. That all works in general, but it looks like this:

So the subplots overwirting parts of the previous ones, although they are not overlaping.

This is my code:

clear();
funcprot(0);
close(winsid());

function [dataFile] = dataReadFromFile(_filename)
    dataStr = csvRead(_filename,',',".","string",[";","";" ",""],[],[],0)
    dataFile = struct()
    
    rowCount = size(dataStr())(1);
    colCount = size(dataStr())(2);
    
    c = 1
    for i = 1:colCount do
        name = dataStr(1,i);
        if name ~= "n.d." then
            idx1 = strindex(name, '[');
            idx2 = strindex(name, ']');
            dataFile(c).nameStr = part(name,1:idx1-1);
            dataFile(c).unitStr = part(name,idx1:idx2);
            dataFile(c).values = [];
            for i=1:rowCount-1 do        // ← -1 and +1 ↓ because of the title row of the data file
                dataFile(c).values(i) = strtod(dataStr(i+1,c));
            end
            c = c+1;
        end
    end
endfunction

refData = dataReadFromFile("FlowControl_Reference_.m")
rawData = dataReadFromFile("FlowControl_Test_.m")

function [] = plotData(_xData, _dataLeftAxis, _lableLeftAxis, _dataRightAxis, _lableRightAxis, _graphIndex, _overwrite, _subplotCoords)
    // _overwrite (boolean) → %T: last figure on the ID _graphIndex will be overwritten
    // _subplotCoords → [nRows, nCols, idx], [1,1,1] makes a single plot
    
    if _overwrite then clf(_graphIndex) end
    scf(_graphIndex)
    f = figure(_graphIndex)
    
    axis = [];
    axis(1) = gca(); // Handle on axes entity
    
    xAxis = _xData.values;
    xmin = min(xAxis);
    xmax = max(xAxis);
    
    yRangeOffsetFactor = 2/5;
    
    secAxis = %F;
    if isempty(_dataRightAxis) == %F then
        secAxis = %T;
    end
    
    if secAxis then axis(2) = newaxes() end
    
    legendItems = [];
    dataL = _dataLeftAxis.values;
    ymin = min(dataL);
    ymax = max(dataL);
    ybound = ymax + (ymax-ymin) * yRangeOffsetFactor; // offset to make space for the legend
    if secAxis then dataR = _dataRightAxis.values end
    if (size(dataL(1))(1)) > 0 then
        subplot(_subplotCoords(1),_subplotCoords(2),_subplotCoords(3))
        legendItems(1) = (msprintf("%s (mean: %.3f, sigma: %.3f)", _lableLeftAxis, mean(dataL), stdev(dataL)));
        if secAxis then legendItems(2) = (msprintf("%s (mean: %.3f, sigma: %.3f)", _lableRightAxis, mean(dataR), stdev(dataR))) end
        data = dataL;
        if secAxis then data = [dataL dataR] end
        plot2d(xAxis, data, rect = [xmin, ymin, xmax, ybound])
        title(_dataLeftAxis.nameStr)
        xlabel("Time [ms]")
        ylabel(_dataLeftAxis.unitStr)
        if size(legendItems)(1) then
            legend(legendItems)
        end
    end
endfunction


plotData(refData(1), refData(3), "Reference", rawData(3), "Test", 1, %T, [1,1,1])
plotData(refData(1), refData(2), "Reference", rawData(2), "Test", 2, %T, [1,2,1])
plotData(refData(1), refData(4), "Reference", rawData(4), "Test", 2, %F, [1,2,2])
plotData(refData(1), refData(5), "Reference", rawData(5), "Test", 3, %T, [1,3,1])
plotData(refData(1), refData(6), "Reference", rawData(6), "Test", 3, %F, [1,3,2])
plotData(refData(1), refData(7), "Reference", rawData(7), "Test", 3, %F, [1,3,3])

FlowControl_Reference_.m looks like this:

"Time [ms]", "Appplication Rate Target [l/ha]", "Application Rate Measured [l/ha]", "Rail Valve Speed [per mill]", "Rail Guard State []", "Rail Valve Pressure [cbar]", "Machine State []", "Rail Valve Following []", "n.d.";
  1000,  555,  246,  0,  0,  250,  53,  1,  0;
  1025,  555,  246,  0,  0,  250,  53,  1,  0;
  1050,  555,  246,  0,  0,  250,  53,  1,  0;
  1075,  555,  246,  0,  0,  250,  53,  1,  0;
  1100,  555,  246,  0,  0,  250,  53,  1,  0;
  1125,  555,  246,  0,  0,  250,  53,  1,  0;
  1150,  555,  246,  0,  0,  250,  53,  1,  0;
  1175,  555,  246,  0,  0,  250,  53,  1,  0;
  1200,  555,  246,  0,  0,  250,  53,  1,  0;
  1225,  555,  246,  0,  0,  250,  53,  1,  0;
  1250,  555,  246,  0,  0,  250,  53,  1,  0;
  1275,  555,  246,  0,  0,  250,  53,  1,  0;
  1300,  555,  246,  0,  0,  250,  53,  1,  0;
  1325,  555,  246,  0,  0,  250,  53,  1,  0;
  1350,  555,  246,  0,  0,  250,  53,  1,  0;
  1375,  555,  246,  0,  0,  250,  53,  1,  0;
  1400,  555,  246,  0,  0,  250,  53,  1,  0;
  1425,  555,  246,  0,  0,  250,  53,  1,  0;
  1450,  555,  246,  0,  0,  250,  53,  1,  0;
  1475,  555,  246,  0,  0,  250,  53,  1,  0;
  1500,  555,  246,  0,  0,  250,  53,  1,  0;
  1525,  555,  246,  0,  0,  250,  53,  1,  0;
  1550,  555,  246,  0,  0,  250,  53,  1,  0;
  1575,  555,  246,  1000,  0,  250,  53,  1,  0;
  1600,  555,  246,  1000,  0,  250,  53,  1,  0;
  1625,  555,  246,  1000,  0,  250,  53,  1,  0;
  1650,  555,  246,  1000,  0,  250,  53,  1,  0;
  1675,  555,  246,  1000,  0,  264,  53,  1,  0;
  1700,  555,  246,  1000,  0,  264,  53,  1,  0;
  1725,  555,  249,  1000,  0,  278,  53,  1,  0;
  1750,  555,  249,  1000,  0,  278,  53,  1,  0;
  1775,  555,  254,  1000,  0,  292,  53,  1,  0;
  1800,  555,  254,  1000,  0,  292,  53,  1,  0;
  1825,  555,  262,  1000,  0,  306,  53,  1,  0;
  1850,  555,  262,  1000,  0,  306,  53,  1,  0;
  1875,  555,  270,  1000,  0,  320,  53,  1,  0;
  1900,  555,  270,  1000,  0,  320,  53,  1,  0;
  1925,  555,  279,  1000,  0,  334,  53,  1,  0;
  1950,  555,  279,  1000,  0,  334,  53,  1,  0;
  1975,  555,  289,  1000,  0,  348,  53,  1,  0;
  2000,  555,  289,  1000,  0,  348,  53,  1,  0;
  2025,  555,  298,  1000,  0,  362,  53,  1,  0;
  2050,  555,  298,  1000,  0,  362,  53,  1,  0;
  2075,  555,  306,  1000,  0,  376,  53,  1,  0;
  2100,  555,  306,  1000,  0,  376,  53,  1,  0;
  2125,  555,  313,  1000,  0,  390,  53,  1,  0;
  2150,  555,  313,  1000,  0,  390,  53,  1,  0;
  2175,  555,  319,  1000,  0,  404,  53,  1,  0;
  2200,  555,  319,  1000,  0,  404,  53,  1,  0;
  2225,  555,  324,  1000,  0,  418,  53,  1,  0;
  2250,  555,  324,  1000,  0,  418,  53,  1,  0;
  2275,  555,  329,  1000,  0,  432,  53,  1,  0;
  2300,  555,  329,  1000,  0,  432,  53,  1,  0;
  2325,  555,  334,  1000,  0,  446,  53,  1,  0;
  2350,  555,  334,  1000,  0,  446,  53,  1,  0;
  2375,  555,  339,  1000,  0,  460,  53,  1,  0;
  2400,  555,  339,  1000,  0,  460,  53,  1,  0;
  2425,  555,  344,  1000,  0,  475,  53,  1,  0;
  2450,  555,  344,  1000,  0,  475,  53,  1,  0;
  2475,  555,  349,  1000,  0,  489,  53,  1,  0;
  2500,  555,  349,  1000,  0,  489,  53,  1,  0;
  2525,  555,  354,  1000,  0,  503,  53,  1,  0;
  2550,  555,  354,  1000,  0,  503,  53,  1,  0;
  2575,  555,  358,  1000,  0,  517,  53,  1,  0;
  2600,  555,  358,  1000,  0,  517,  53,  1,  0;
  2625,  555,  364,  1000,  0,  531,  53,  1,  0;
  2650,  555,  364,  1000,  0,  531,  53,  1,  0;
  2675,  555,  368,  1000,  0,  545,  53,  1,  0;
  2700,  555,  368,  1000,  0,  545,  53,  1,  0;
  2725,  555,  373,  1000,  0,  559,  53,  1,  0;
  2750,  555,  373,  1000,  0,  559,  53,  1,  0;
  2775,  555,  377,  1000,  0,  573,  53,  1,  0;
  2800,  555,  377,  1000,  0,  573,  53,  1,  0;
  2825,  555,  382,  1000,  0,  587,  53,  1,  0;
  2850,  555,  382,  1000,  0,  587,  53,  1,  0;
  2875,  555,  386,  1000,  0,  601,  53,  1,  0;
  2900,  555,  386,  1000,  0,  601,  53,  1,  0;
  2925,  555,  390,  1000,  0,  615,  53,  1,  0;
  2950,  555,  390,  1000,  0,  615,  53,  1,  0;
  2975,  555,  395,  1000,  0,  629,  53,  1,  0;
  3000,  555,  395,  1000,  0,  629,  53,  1,  0;
  3025,  555,  399,  1000,  0,  643,  53,  1,  0;
  3050,  555,  399,  1000,  0,  643,  53,  1,  0;
  3075,  555,  403,  1000,  0,  657,  53,  1,  0;
  3100,  555,  403,  1000,  0,  657,  53,  1,  0;
  3125,  555,  408,  1000,  0,  671,  53,  1,  0;
  3150,  555,  408,  1000,  0,  671,  53,  1,  0;
  3175,  555,  412,  1000,  0,  685,  53,  1,  0;
  3200,  555,  412,  1000,  0,  685,  53,  1,  0;
  3225,  555,  416,  1000,  0,  700,  53,  1,  0;
  3250,  555,  416,  1000,  0,  700,  53,  1,  0;
  3275,  555,  420,  1000,  0,  714,  53,  1,  0;
  3300,  555,  420,  1000,  0,  714,  53,  1,  0;
  3325,  555,  424,  1000,  0,  728,  53,  1,  0;
  3350,  555,  424,  1000,  0,  728,  53,  1,  0;
  3375,  555,  428,  1000,  0,  742,  53,  1,  0;
  3400,  555,  428,  1000,  0,  742,  53,  1,  0;
  3425,  555,  432,  1000,  0,  756,  53,  1,  0;
  3450,  555,  432,  1000,  0,  756,  53,  1,  0;
  3475,  555,  436,  1000,  0,  770,  53,  1,  0;
  3500,  555,  436,  1000,  0,  770,  53,  1,  0;
  3525,  555,  440,  1000,  0,  784,  53,  1,  0;
  3550,  555,  440,  1000,  0,  784,  53,  1,  0;
  3575,  555,  443,  1000,  0,  798,  53,  1,  0;
  3600,  555,  443,  1000,  0,  798,  53,  1,  0;
  3625,  555,  447,  1000,  0,  812,  53,  1,  0;
  3650,  555,  447,  1000,  0,  812,  53,  1,  0;
  3675,  555,  451,  1000,  0,  826,  53,  1,  0;
  3700,  555,  451,  1000,  0,  826,  53,  1,  0;
  3725,  555,  455,  1000,  0,  840,  53,  1,  0;
  3750,  555,  455,  1000,  0,  840,  53,  1,  0;
  3775,  555,  458,  1000,  0,  854,  53,  1,  0;
  3800,  555,  458,  1000,  0,  854,  53,  1,  0;
  3825,  555,  462,  1000,  0,  868,  53,  1,  0;
  3850,  555,  462,  1000,  0,  868,  53,  1,  0;
  3875,  555,  466,  1000,  0,  882,  53,  1,  0;
  3900,  555,  466,  1000,  0,  882,  53,  1,  0;
  3925,  555,  469,  1000,  0,  896,  53,  1,  0;
  3950,  555,  469,  1000,  0,  896,  53,  1,  0;
  3975,  555,  473,  1000,  0,  910,  53,  1,  0;
  4000,  555,  473,  1000,  0,  910,  53,  1,  0;
  4025,  555,  477,  1000,  0,  925,  53,  1,  0;
  4050,  555,  477,  1000,  0,  925,  53,  1,  0;
  4075,  555,  480,  1000,  0,  939,  53,  1,  0;
  4100,  555,  480,  1000,  0,  939,  53,  1,  0;
  4125,  555,  484,  1000,  0,  953,  53,  1,  0;
  4150,  555,  484,  1000,  0,  953,  53,  1,  0;
  4175,  555,  487,  1000,  0,  967,  53,  1,  0;
  4200,  555,  487,  1000,  0,  967,  53,  1,  0;
  4225,  555,  491,  1000,  0,  981,  53,  1,  0;
  4250,  555,  491,  1000,  0,  981,  53,  1,  0;
  4275,  555,  494,  1000,  0,  995,  53,  1,  0;
  4300,  555,  494,  1000,  0,  995,  53,  1,  0;
  4325,  555,  498,  1000,  0,  1009,  53,  1,  0;
  4350,  555,  498,  1000,  0,  1009,  53,  1,  0;
  4375,  555,  501,  1000,  0,  1023,  53,  1,  0;
  4400,  555,  501,  1000,  0,  1023,  53,  1,  0;
  4425,  555,  504,  1000,  0,  1037,  53,  1,  0;
  4450,  555,  504,  1000,  0,  1037,  53,  1,  0;
  4475,  555,  508,  1000,  0,  1051,  53,  1,  0;
  4500,  555,  508,  1000,  0,  1051,  53,  1,  0;
...

FlowControl_Test_.m looks like this:

"Time [ms]", "Appplication Rate Target [l/ha]", "Application Rate Measured [l/ha]", "Rail Valve Speed [per mill]", "Rail Guard State []", "Rail Valve Pressure [cbar]", "Machine State []", "Rail Valve Following []", "n.d.";
  1000,  555,  245,  0,  0,  249,  53,  1,  0;
  1025,  555,  245,  0,  0,  249,  53,  1,  0;
  1050,  555,  245,  0,  0,  249,  53,  1,  0;
  1075,  555,  245,  0,  0,  249,  53,  1,  0;
  1100,  555,  245,  0,  0,  249,  53,  1,  0;
  1125,  555,  245,  0,  0,  249,  53,  1,  0;
  1150,  555,  245,  0,  0,  249,  53,  1,  0;
  1175,  555,  245,  0,  0,  249,  53,  1,  0;
  1200,  555,  245,  0,  0,  249,  53,  1,  0;
  1225,  555,  245,  0,  0,  249,  53,  1,  0;
  1250,  555,  245,  0,  0,  249,  53,  1,  0;
  1275,  555,  245,  0,  0,  249,  53,  1,  0;
  1300,  555,  245,  0,  0,  249,  53,  1,  0;
  1325,  555,  245,  0,  0,  249,  53,  1,  0;
  1350,  555,  245,  0,  0,  249,  53,  1,  0;
  1375,  555,  245,  0,  0,  249,  53,  1,  0;
  1400,  555,  245,  0,  0,  249,  53,  1,  0;
  1425,  555,  245,  0,  0,  249,  53,  1,  0;
  1450,  555,  245,  0,  0,  249,  53,  1,  0;
  1475,  555,  245,  0,  0,  249,  53,  1,  0;
  1500,  555,  245,  0,  0,  249,  53,  1,  0;
  1525,  555,  245,  0,  0,  249,  53,  1,  0;
  1550,  555,  245,  0,  0,  249,  53,  1,  0;
  1575,  555,  245,  350,  0,  249,  53,  1,  0;
  1600,  555,  245,  350,  0,  249,  53,  1,  0;
  1625,  555,  245,  400,  0,  249,  53,  1,  0;
  1650,  555,  245,  400,  0,  249,  53,  1,  0;
  1675,  555,  245,  450,  0,  249,  53,  1,  0;
  1700,  555,  245,  450,  0,  249,  53,  1,  0;
  1725,  555,  245,  500,  0,  249,  53,  1,  0;
  1750,  555,  245,  500,  0,  249,  53,  1,  0;
  1775,  555,  245,  550,  0,  249,  53,  1,  0;
  1800,  555,  245,  550,  0,  249,  53,  1,  0;
  1825,  555,  245,  600,  0,  249,  53,  1,  0;
  1850,  555,  245,  600,  0,  249,  53,  1,  0;
  1875,  555,  245,  650,  0,  249,  53,  1,  0;
  1900,  555,  245,  650,  0,  249,  53,  1,  0;
  1925,  555,  245,  700,  0,  249,  53,  1,  0;
  1950,  555,  245,  700,  0,  249,  53,  1,  0;
  1975,  555,  245,  750,  0,  249,  53,  1,  0;
  2000,  555,  245,  750,  0,  249,  53,  1,  0;
  2025,  555,  245,  800,  0,  249,  53,  1,  0;
  2050,  555,  245,  800,  0,  249,  53,  1,  0;
  2075,  555,  245,  850,  0,  249,  53,  1,  0;
  2100,  555,  245,  850,  0,  249,  53,  1,  0;
  2125,  555,  245,  900,  0,  249,  53,  1,  0;
  2150,  555,  245,  900,  0,  249,  53,  1,  0;
  2175,  555,  245,  950,  0,  249,  53,  1,  0;
  2200,  555,  245,  950,  0,  249,  53,  1,  0;
  2225,  555,  245,  1000,  0,  249,  53,  1,  0;
  2250,  555,  245,  1000,  0,  249,  53,  1,  0;
  2275,  555,  245,  1000,  0,  249,  53,  1,  0;
  2300,  555,  245,  1000,  0,  249,  53,  1,  0;
  2325,  555,  245,  1000,  0,  249,  53,  1,  0;
  2350,  555,  245,  1000,  0,  249,  53,  1,  0;
  2375,  555,  245,  1000,  0,  249,  53,  1,  0;
  2400,  555,  245,  1000,  0,  249,  53,  1,  0;
  2425,  555,  245,  1000,  0,  249,  53,  1,  0;
  2450,  555,  245,  1000,  0,  249,  53,  1,  0;
  2475,  555,  245,  1000,  0,  249,  53,  1,  0;
  2500,  555,  245,  1000,  0,  249,  53,  1,  0;
  2525,  555,  245,  1000,  0,  249,  53,  1,  0;
  2550,  555,  245,  1000,  0,  249,  53,  1,  0;
  2575,  555,  245,  1000,  0,  249,  53,  1,  0;
  2600,  555,  245,  1000,  0,  249,  53,  1,  0;
  2625,  555,  245,  1000,  0,  249,  53,  1,  0;
  2650,  555,  245,  1000,  0,  249,  53,  1,  0;
  2675,  555,  245,  1000,  0,  249,  53,  1,  0;
  2700,  555,  245,  1000,  0,  249,  53,  1,  0;
  2725,  555,  245,  1000,  0,  249,  53,  1,  0;
  2750,  555,  245,  1000,  0,  249,  53,  1,  0;
  2775,  555,  245,  1000,  0,  249,  53,  1,  0;
  2800,  555,  245,  1000,  0,  249,  53,  1,  0;
  2825,  555,  245,  1000,  0,  249,  53,  1,  0;
  2850,  555,  245,  1000,  0,  249,  53,  1,  0;
  2875,  555,  245,  1000,  0,  249,  53,  1,  0;
  2900,  555,  245,  1000,  0,  249,  53,  1,  0;
  2925,  555,  245,  1000,  0,  249,  53,  1,  0;
  2950,  555,  245,  1000,  0,  249,  53,  1,  0;
  2975,  555,  245,  1000,  0,  249,  53,  1,  0;
  3000,  555,  245,  1000,  0,  249,  53,  1,  0;
  3025,  555,  245,  1000,  0,  249,  53,  1,  0;
  3050,  555,  245,  1000,  0,  249,  53,  1,  0;
  3075,  555,  245,  1000,  0,  249,  53,  1,  0;
  3100,  555,  245,  1000,  0,  249,  53,  1,  0;
  3125,  555,  245,  1000,  0,  249,  53,  1,  0;
  3150,  555,  245,  1000,  0,  249,  53,  1,  0;
  3175,  555,  245,  1000,  0,  249,  53,  1,  0;
  3200,  555,  245,  1000,  0,  249,  53,  1,  0;
  3225,  555,  245,  1000,  0,  249,  53,  1,  0;
  3250,  555,  245,  1000,  0,  249,  53,  1,  0;
  3275,  555,  245,  1000,  0,  249,  53,  1,  0;
  3300,  555,  245,  1000,  0,  249,  53,  1,  0;
  3325,  555,  245,  1000,  0,  249,  53,  1,  0;
  3350,  555,  245,  1000,  0,  249,  53,  1,  0;
  3375,  555,  245,  1000,  0,  249,  53,  1,  0;
  3400,  555,  245,  1000,  0,  249,  53,  1,  0;
  3425,  555,  245,  1000,  0,  249,  53,  1,  0;
  3450,  555,  245,  1000,  0,  249,  53,  1,  0;
  3475,  555,  245,  1000,  0,  249,  53,  1,  0;
  3500,  555,  245,  1000,  0,  249,  53,  1,  0;
  3525,  555,  245,  1000,  0,  249,  53,  1,  0;
  3550,  555,  245,  1000,  0,  249,  53,  1,  0;
  3575,  555,  245,  1000,  0,  249,  53,  1,  0;
  3600,  555,  245,  1000,  0,  249,  53,  1,  0;
  3625,  555,  245,  1000,  0,  249,  53,  1,  0;
  3650,  555,  245,  1000,  0,  249,  53,  1,  0;
  3675,  555,  245,  1000,  0,  249,  53,  1,  0;
  3700,  555,  245,  1000,  0,  249,  53,  1,  0;
  3725,  555,  245,  1000,  0,  249,  53,  1,  0;
  3750,  555,  245,  1000,  0,  249,  53,  1,  0;
  3775,  555,  245,  1000,  0,  249,  53,  1,  0;
  3800,  555,  245,  1000,  0,  249,  53,  1,  0;
  3825,  555,  245,  1000,  0,  249,  53,  1,  0;
  3850,  555,  245,  1000,  0,  249,  53,  1,  0;
  3875,  555,  245,  1000,  0,  255,  53,  1,  0;
  3900,  555,  245,  1000,  0,  255,  53,  1,  0;
  3925,  555,  246,  1000,  0,  270,  53,  1,  0;
  3950,  555,  246,  1000,  0,  270,  53,  1,  0;
  3975,  555,  250,  1000,  0,  283,  53,  1,  0;
  4000,  555,  250,  1000,  0,  283,  53,  1,  0;
  4025,  555,  256,  1000,  0,  297,  53,  1,  0;
  4050,  555,  256,  1000,  0,  297,  53,  1,  0;
  4075,  555,  265,  1000,  0,  312,  53,  1,  0;
  4100,  555,  265,  1000,  0,  312,  53,  1,  0;
  4125,  555,  274,  1000,  0,  325,  53,  1,  0;
  4150,  555,  274,  1000,  0,  325,  53,  1,  0;
  4175,  555,  283,  1000,  0,  339,  53,  1,  0;
  4200,  555,  283,  1000,  0,  339,  53,  1,  0;
  4225,  555,  292,  1000,  0,  354,  53,  1,  0;
  4250,  555,  292,  1000,  0,  354,  53,  1,  0;
  4275,  555,  301,  1000,  0,  367,  53,  1,  0;
  4300,  555,  301,  1000,  0,  367,  53,  1,  0;
  4325,  555,  308,  1000,  0,  381,  53,  1,  0;
  4350,  555,  308,  1000,  0,  381,  53,  1,  0;
  4375,  555,  314,  1000,  0,  396,  53,  1,  0;
  4400,  555,  314,  1000,  0,  396,  53,  1,  0;
  4425,  555,  320,  1000,  0,  411,  53,  1,  0;
  4450,  555,  320,  1000,  0,  411,  53,  1,  0;
  4475,  555,  325,  1000,  0,  424,  53,  1,  0;
  4500,  555,  325,  1000,  0,  424,  53,  1,  0;
  4525,  555,  330,  1000,  0,  438,  53,  0,  0;
  4550,  555,  330,  1000,  0,  438,  53,  0,  0;
  4575,  555,  335,  0,  1,  453,  53,  1,  0;
  4600,  555,  335,  0,  1,  453,  53,  1,  0;
  4625,  555,  340,  0,  1,  466,  53,  1,  0;
  4650,  555,  340,  0,  1,  466,  53,  1,  0;
  4675,  555,  345,  0,  1,  466,  53,  1,  0;
...

I would give you the full file but I’m not authorised to do that.

Can someone help me with this?

Thank you

Hello, welcome to this forum !

I had a quick look to your code and saw that you are using at the same time newaxes and subplot: to me that’s a bad idea because most of the time subplot creates new Axes entities, this may be the source of your problem. Maybe you missed the existence of sca() (see sca - Set the current axes entity) which serves to make a given Axes the current one, which is necessary when you want to later use a given plotting function like plot2d.

S.

1 Like

Thanks a lot for the responding so fast. The second axis was remaining from another (still) unsolved problem… so you helped a lot to set the focus on that :smiley:

This is my code now:

function [] = plotData(_xData, _dataLeftAxis, _lableLeftAxis, _dataRightAxis, _lableRightAxis, _graphIndex, _overwrite, _subplotCoords)
    // _overwrite (boolean) → %T: last figure on the ID _graphIndex will be overwritten
    // _subplotCoords → [nRows, nCols, idx], [1,1,1] makes a single plot
    
    if _overwrite then clf(_graphIndex) end
    scf(_graphIndex)
    f = figure(_graphIndex)
    
    axis(1) = gca(); // Handle on axes entity
    
    xAxis = _xData.values;
    xmin = min(xAxis);
    xmax = max(xAxis);
    dataL = _dataLeftAxis.values;
    y1min = min(dataL);
    y1max = max(dataL);
    y1Range = [y1min, y1max];
    
    yRangeOffsetFactor = 2/5;
    y1bound = y1max + (y1max-y1min) * yRangeOffsetFactor; // offset to make space for the legend
    
    legendItems = [];
    if (size(dataL(1))(1)) > 0 then
        subplot(_subplotCoords(1),_subplotCoords(2),_subplotCoords(3))
        plot2d(xAxis, dataL, rect = [xmin, y1min, xmax, y1bound])
        legendItems(1) = (msprintf("%s (mean: %.3f, sigma: %.3f)", _lableLeftAxis, mean(dataL), stdev(dataL)));
        title(_dataLeftAxis.nameStr)
        xlabel("Time [ms]")
        ylabel(_dataLeftAxis.unitStr)
        
        if isempty(_dataRightAxis) == %F then
            axis(2) = newaxes()
            c = color("red")
            axis(2).font_color = c
            axis(2).filled = "off";
            axis(2).axes_visible(1) = "off";
            axis(2).y_location = "right";
            dataR = _dataRightAxis.values
            y2min = min(dataR);
            y2max = max(dataR);
            y2Range = [y2min, y2max];
            y2bound = y2max + (y2max-y2min) * yRangeOffsetFactor;
            subplot(_subplotCoords(1),_subplotCoords(2),_subplotCoords(3))
            plot2d(xAxis, dataR, rect = [xmin, y2min, xmax, y2bound], style = c)
            legendItems(2) = (msprintf("%s (mean: %.3f, sigma: %.3f)", _lableRightAxis, mean(dataR), stdev(dataR)))
            ylabel(_dataRightAxis.unitStr)
        end
        
        if size(legendItems)(1) then
            legend(legendItems)
        end
    end
endfunction
1 Like