How can I modify a curve in a plot via Python?

Category:
Scripting
Summary

This article describes how to modify a curve in a plot in PowerFactory via Python to change for example the colour, line style or the depicted variables and elements of curves.

Answer

Changing the colour, line style or elements in an existing plot via Python can be done by modifying the Data Series object of a plot. The Data Series object contains the information for all shown curves within a plot. The plot object itself is contained in the page object (GrpPage). The class of the plot object depends on the type of plot (e.g. PltLinebarplot for standard curve plots). The objects can be accessed as follows:

plotObject = grpPage.GetOrInsertPlot('MyPlotName', 1)
pltDataseries = plotObject.GetDataSeries()

The recommended approach to add new curves is to use the AddCurve function of the plot objects.

The attributes defining the curves are part of a table which consists of multiple list attributes shown as the columns. Each row of the table corresponds to a curve. The attribute names can be found by hovering over the column headers of the Data Series object, which can be found by double-clicking on a plot in PowerFactory. Some examples are:

  • curveTableElement: Elements for which a variable should be plotted (PowerFactory object)
  • curveTableVariable: Variables that should be plotted (string)
  • curveTableResultFile: Specifies the result object containing the values (ElmRes object, requires attribute pltDataseries.useIndividualResults = 1)
  • curveTableColour: Colour of the curve (encoded integer available via app.EncodeColour(int red, int green, int blue, [int alpha = 255]))
  • curveTableLineStyle: Line style of the curve (i.e. solid, dashed, etc. as integer values)
  • curveTableLineWidth: Line width of the curve (as integer value; hairline = 0, 0.1 = 10, 0.5 = 50, ...)
  • curveTableLabel: Label of the curve (string)

Similarly, the curve shape and data transformation of curves can be set via such attributes, if the respective plot features are selected.

The values of the attributes can be changed in two different ways, as shown in the following example for the colour:

  1. For changing all values, a list of colour values can be passed:

pltDataseries.SetAttribute('curveTableColor', [-15572290, -1172706, -14636533])

  1. Changing individual values can be done by indexing:

pltDataseries.SetAttribute('curveTableColor:1', -15572290)

Back