0% found this document useful (0 votes)
143 views4 pages

GNU Plot Example

This document describes PyGnuplot, a Python module that allows Python code to generate and modify Gnuplot graphs. It can save data arrays to files, plot data by sending commands to Gnuplot, and output figures in common formats like PostScript and PDF. Functions are provided to pipe commands to Gnuplot, save data files, plot data, and manage figures. Examples demonstrate basic usage like plotting sine waves and saving the results to a PostScript file.

Uploaded by

Ln Amitav Biswas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views4 pages

GNU Plot Example

This document describes PyGnuplot, a Python module that allows Python code to generate and modify Gnuplot graphs. It can save data arrays to files, plot data by sending commands to Gnuplot, and output figures in common formats like PostScript and PDF. Functions are provided to pipe commands to Gnuplot, save data files, plot data, and manage figures. Examples demonstrate basic usage like plotting sine waves and saving the results to a PostScript file.

Uploaded by

Ln Amitav Biswas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Requires:

Gnuplot (http://www.gnuplot.info)

numpy

Installation:

Using pip

pip install PyGnuplot

Using conda

conda install -c benschneider pygnuplot

Upgrade:

pip install --upgrade PyGnuplot

Functions:

c(command)
pipe a command to gnuplot as if in gnuplot command promt

c('plot sin(x)')

s(data, filename=’tmp.dat’)
save arrays into file (filename = ‘tmp.dat’) easily read by Gnuplot

s([X,Y,Z]) # creates tmp.dat


c('plot "tmp.dat" u 1:2')

plot(data, filename=’tmp.dat’)
Plot some data. Saves data into filename (default = ‘tmp.dat’) and then sends plot
instructions to Gnuplot

plot([x,y])

figure(number=None, term=’x11’)
Create a new or update a figure

figure(1)

p(filename=’tmp.ps’, width=14, height=9, fontsize=12, term=’x11’)


Create postscript file (overwrites existing)

p('myfile.ps')

pdf(filename=’tmp.pdf’, width=14, height=9, fontsize=12, term=’x11’)


Create a pdf file (overwrites existing)

pdf('myfile.pdf')

Setup terminal
Default terminal is ‘x11’ unless defined otherwise i.e. for windows:

import PyGnuplot as gp

gp.default_term = 'wxt'

Examples:

 1 Example code
import PyGnuplot as gp

import numpy as np

X = np.arange(10)

Y = np.sin(X/(2*np.pi))

Z = Y**2.0

gp.s([X,Y,Z])

gp.c('plot "tmp.dat" u 1:2 w lp)

gp.c('replot "tmp.dat" u 1:3' w lp)

gp.p('myfigure.ps')

 2 Example file

python example.py

You might also like