Graphics, when used correctly, can be the difference between an outstanding report and simply another piece of paper going around the office. The only thing more professional than a nice graphic, is a graphic that is automatically generated.
Exporting plots from the PSSE graphical interface can be a laborious task, with little flexibility in the final result. If you are running PSSE from Python, you have the option of looking beyond PSSE for tools to render your data.
matplotlib is a Python plotting tool which, given a little bit of effort, can make your life easier by automating figure generation; spend the time to get it right once, then generate the monthly figures with the press of a button.
matplotlib’s syntax is closely aligned with Matlab’s, which is fortunate if you are familiar with Matlab. If you are not familiar with them, don’t worry, the matplotlib community has provide an excellent tutorial and gallery displaying the immense possibilities of matplotlib (all examples come with code included for you to use as a starting point).
I’ll use matplotlib to create this chart:
It is the QV curve at bus 20001 (my favourite bus as it happens) and was plotted from data kept in a CSV file (qv.csv).
Here is the code we used to create that chart.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
I’m using the pylab
module of matplotlib. The pylab
module most
closely resembles Matlab code so its a really familiar place to
start learning how to use matplotlib.
The first two sections open up the CSV file and convert it into
a list of voltage
and reactive
floating point values.
Now, I’ll pull a section of that code out so that we can look closely:
1 2 3 4 5 6 7 |
|
Thats the code that actually turns the lists of voltages
and reactive
values into a chart. The functions describe themselves pretty well.
At the end of the routine show
will pop up an interactive graph.
With the interactive graph you can:
- zoom in and out;
- pan around; and
- export the chart to an image file.
If you haven’t ever used matplotlib go ahead and try this example out. Before you do run the Python code here, just make sure you have both matplotlib and numpy installed. Install numpy first because matplotlib definitely needs it and will not install without it.
You’ve seen how easy it can be to start making your own charts with matplotlib. The quality of the resulting images is really exceptional. We’ve used them throughout many industry published documents. If you have any questions about making your own charts, jump onto our forum for power systems engineers we’ll help you out.
If you made it this far, you must be pretty keen on Python. We are too! Let us update you when we have something new to say about Python and Power Systems (semi regularly). Get Python Tips (subscribe on the right) →