Gnuplot-py Usage
Posted: Wed Jul 20, 2016 4:57 pm
Gnuplot.py is a Python interface to Gnuplot. You need to install Python, Numpy and Gnuplot as dependencies to be able to use Gnuploty.py. Gnuplot.py allows data computed in Python to be directly and interactively plotted using Gnuplot.
The following is the demo how to use Gnuplot.py
This should produce
The following is the demo how to use Gnuplot.py
- #! /usr/bin/env python
- import numpy as np
- import Gnuplot
- #Create some data
- x = np.linspace(0, 10, 100)
- y1 = x**2
- y2 = 10*np.sin(np.pi*x)
- #Instantiate Gnuplot object
- g = Gnuplot.Gnuplot(persist=1) #try persist = 0
- #Create the Gnuplot data
- data1 = Gnuplot.Data(x, y1, with_ ='lp', title = 'Exponential function')
- data2 = Gnuplot.Data(x, y2, with_ = 'l', title = 'Sinusoid function')
- #Formatting options
- g('set grid')
- g('set key left')
- g('set xlabel "x variable"')
- g('set ylabel "f(x)"')
- g('set title "Gnuplot.py Demo"')
- #Plot
- g.plot(data1, data2)
- #save hardcopy, pass the raw terminal definition string to gnuplot
- #Try to replace the lines below by g.hardcopy("demo1.svg", terminal='svg', size=[800,400])
- g('set terminal pngcairo size 800,400') #set terminal to pngCairo
- g.set_string('output', 'demo1.png')
- g.refresh()
- g.set_string('output')