Search code examples
plotmodelicadymolaopenmodelica

Adding extra vertical line to the existing Dymola plot


I have a graph which looks like this:

Dymola Plot

Please note that x-axis is NOT time but an arbitrary independent variable.

I need to draw vertical lines shown in the image above and label them. How can this be done in Dymola using the mos script?

Thank you!


Solution

  • I couldn't find anything else than manually adding a line via plotArray() the accompanying text by plotText(). See the Dymola-specific .mos-script below which should generate the plot at end.

    // Simulate the model
    simulateModel("Modelica.Mechanics.Rotational.Examples.CoupledClutches", stopTime=1.5, numberOfIntervals=0, outputInterval=0.001, resultFile="CoupledClutches");
    
    // Create the actual plot
    createPlot(id=1, position={191, 39, 672, 423}, x="clutch1.tau", y={"clutch1.phi_rel", "clutch1.w_rel"}, range={-10.0, 4.0, -200.0, 20.0}, grid=true, colors={{28,108,200}, {238,46,47}}, displayUnits={"deg", ""});
    
    // Add the vertical line
    plotArray(x={-8,-8},y={-200,0},color={0,128,0},thickness=0.5, erase=false);
    plotArray(x={-2,-2},y={-200,0},color={128,0,128},thickness=0.5, erase=false);
    
    // Add text
    plotText(id=1, extent={{-9,-210}, {-7,-220}}, textString="Description 01", lineColor={0,128,0});
    plotText(id=1, extent={{-3,-210}, {-1,-220}}, textString="Description 02", lineColor={128,0,128});
    

    Plot created by the code above

    If you want to use the legend for the description as you did in your mock-up, use the 'legend'-string parameter of the plotArray()-function instead of manually adding the text.

    The script could for sure be enhanced by some more sophisticated dimensions for the arrays and texts, but this should be a good starting point. Also using plotArrays() combine the lines for the vertical lines.