Page 1 of 1

Gnuplot-py Usage

Posted: Wed Jul 20, 2016 4:57 pm
by Eli
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
  1. #! /usr/bin/env python
  2.  
  3. import numpy as np
  4. import Gnuplot
  5.  
  6. #Create some data
  7. x = np.linspace(0, 10, 100)
  8. y1 = x**2
  9. y2 = 10*np.sin(np.pi*x)
  10.  
  11. #Instantiate Gnuplot object
  12. g = Gnuplot.Gnuplot(persist=1) #try persist = 0
  13.  
  14. #Create the Gnuplot data
  15. data1 = Gnuplot.Data(x, y1, with_ ='lp', title = 'Exponential function')
  16. data2 = Gnuplot.Data(x, y2, with_ = 'l', title = 'Sinusoid function')
  17.  
  18. #Formatting options
  19. g('set grid')
  20. g('set key left')
  21. g('set xlabel "x variable"')
  22. g('set ylabel "f(x)"')
  23. g('set title "Gnuplot.py Demo"')
  24.  
  25. #Plot
  26. g.plot(data1, data2)
  27.  
  28. #save hardcopy, pass the raw terminal definition string to gnuplot
  29. #Try to replace the lines below by g.hardcopy("demo1.svg", terminal='svg', size=[800,400])
  30. g('set terminal pngcairo size 800,400') #set terminal to pngCairo
  31. g.set_string('output', 'demo1.png')
  32. g.refresh()
  33. g.set_string('output')

This should produce
demo1.png

Re: Gnuplot-py Usage

Posted: Sat Jul 30, 2016 4:32 pm
by 1/0
Super nice plotting!