Gnuplot is a portable command-line driven graphing utility for Linux, OS/2, MS Windows, OSX, VMS, and many other platforms. The source code is copyrighted but freely distributed (i.e., you don’t have to pay for it). It was originally created to allow scientists and students to visualize mathematical functions and data interactively, but has grown to support many non-interactive uses such as web scripting
Gnuplot can be opened as a subprocess within a Python script.
The follow lines of code are required for the case of the sample program running in Windows or Linux:
from subprocess import Popen, PIPE
if platform.system() == ‘Windows’ or platform.system() == ‘Linux’:
- if platform.system() == ‘Windows’:
- gnuplot = r’C:\Program Files (x86)\gnuplot\bin\pgnuplot’
- if platform.system() == ‘Linux’:
- # do some plot commands common to Windows & Linux
Here is the sample script which generates a gnuplot file, saves it to a folder, then loads it into gnuplot.