Gnuplot-py Usage

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

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
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
1/0
Member
Reactions: 0
Posts: 3
Joined: 7 years ago

#2

Super nice plotting!
0
Post Reply

Return to “Gnuplot, Maxima/XMaxima”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests