Menu

Creating 2-dimensional plot in DWSIM

The One
2019-07-08
2019-08-12
  • The One

    The One - 2019-07-08

    How can i create a 2-dimensional plot in DWSIM given 2 arrays of same size?

     
    • Daniel Medeiros

      Daniel Medeiros - 2019-08-07

      On Python?

       
  • Luca Finardi

    Luca Finardi - 2019-08-11

    Hello,
    I also tried several ways to chart data with a DWSIM script.
    But for what I found, matplotlib can't be used, and ironplot library doesn't work (it gives an error that I don't know how to solve).

    Eventually I found and adapted a very basic procedure that produces 2D plots with MSChart.
    In the attached DWSIM simulation you will find a script that allows to obtain graphs once the data series are populated in the relevant part of the script.

    It could be nice to have a charting plugin in the next DWSIM releases.
    Hope this helps you.

    Luca

     
  • The One

    The One - 2019-08-11

    Thanks a lot Luca Finardi

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-08-11

    Guys, check the dynamic simulation tutorial, there are a lot of 2d charting examples on it.

     
  • Luca Finardi

    Luca Finardi - 2019-08-11

    Thanks Daniel for addressing to OxyPlot included in the Dynamic tutorial.

    However I could not make it it working. I tried this simple:

    import sys
    sys.path.append(r"./Lib")
    import site
    import os

    import clr
    clr.AddReference("Eto.OxyPlot")
    clr.AddReference("OxyPlot")

    import OxyPlot
    from Eto.OxyPlot import Plot

    from math import *
    x = [i * 0.1 for i in range(100)]

    chart1 = Plot()
    chart1.Model = Common.CreatePlotModel(x, [sin(xi) for xi in x], "Plot1", "", "x", "Sin(x)")
    chart1.Model.InvalidatePlot(True)

    form1 = Common.GetDefaultEditorForm("Test", 600, 600, chart1, False)
    form1.Show()

    but I got the error:
    Error running script: Traceback (most recent call last):
    File "<string>", line 16, in <module>
    ValueError: Specified argument was out of the range of valid values.
    Parameter name: Type for 'Eto.OxyPlot.Plot' could not be found in this platform </module></string>

    Any suggestion? (I am using DW 5.7u14)
    Thanks

    Luca

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-08-11

    Sorry guys, the code in the dynamic tutorial only works on the Cross-Platform UI. For the Classic UI (Windows Forms), try the following:

    import sys
    sys.path.append(r"./Lib") 
    import site
    import os
    
    import clr
    
    clr.AddReference("OxyPlot")
    clr.AddReference("OxyPlot.WindowsForms")
    clr.AddReference("System.Windows.Forms")
    clr.AddReference("DWSIM.ExtensionMethods.Eto")
    
    import OxyPlot
    
    from OxyPlot.WindowsForms import PlotView
    from System.Windows.Forms import *
    from DWSIM.UI.Shared import *
    from System import Array
    
    from math import * 
    x = [i * 0.1 for i in range(100)]
    
    # generate and display a nice chart
    
    # create a new Plot model
    
    # http://dwsim.inforside.com.br/api_help5/html/T_DWSIM_UI_Shared_Common.htm
    # http://dwsim.inforside.com.br/api_help5/html/T_DWSIM_ExtensionMethods_OxyPlot.htm
    
    chart1 = PlotView()
    chart1.Model = Common.CreatePlotModel(Array[float](x), Array[float]([sin(xi) for xi in x]), "Test", "", "x", "y") 
    
    # update the chart data view
    
    chart1.Model.InvalidatePlot(True)
    
    # setup and display the chart
    
    form1 = Form()
    
    chart1.Dock = DockStyle.Fill
    
    form1.Controls.Add(chart1)
    form1.Invalidate()
    form1.Show()
    
     
    👍
    1

    Last edit: Daniel Medeiros 2019-08-11
  • Luca Finardi

    Luca Finardi - 2019-08-12

    Thanks Daniel for this clarification.
    I tried your example with the classic UI, but to me it only shows an empty form (see attachment).

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-08-12

    Try resizing the form. The Invalidate() call is responsible for updating the form contents. I've tested it here and it worked as expected.

     
  • Luca Finardi

    Luca Finardi - 2019-08-12

    Here instead the form does not resize and after a while disappears.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.