Skip to content
Snippets Groups Projects
Commit 9834e944 authored by Josué Ortega's avatar Josué Ortega :fish_cake:
Browse files

Import Upstream version 0.11.16

parents
No related branches found
No related tags found
No related merge requests found
setup.cfg
*.swp
*.pyc
*.out
*.pdf
.ropeproject
build/
dist/
PyGnuplot.egg-info/
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
# PyPy versions
- "pypy" # PyPy2 2.5.0
- "pypy3" # Pypy3 2.4.0
- "pypy-5.3.1"
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "sudo apt-get install gnuplot-x11"
install:
- pip install .
- pip install numpy
- pip install nose coverage
# - pip install coveralls
# - pip install pypiview
# command to run tests
script:
- python example.py
- python setup.py nosetests --cover-package pypiview # --with-coverage
#after_sucess:
#coveralls
The MIT License (MIT)
Copyright (c) 2016 Ben Schneider
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
include LICENSE
include README.rst
include example.py
'''
By Ben Schneider
Simple python wrapper for Gnuplot
Thanks to steview2000 for suggesting to separate processes,
jrbrearley for help with debugging in python 3.4+
Example:
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]) # saves data into tmp.dat
gp.c('plot "tmp.dat" u 1:2 w lp) # send 'plot instructions to gnuplot'
gp.c('replot "tmp.dat" u 1:3' w lp)
gp.p('myfigure.ps') # creates postscript file
'''
from subprocess import Popen as _Popen, PIPE as _PIPE
default_term = 'x11' # change this if you use a different terminal
class _FigureList(object):
def __init__(self):
proc = _Popen(['gnuplot', '-p'], shell=False, stdin=_PIPE, universal_newlines=True) # persitant -p
self.instance = {0 : [proc, default_term]} # {figure number : [process, terminal type]}
self.n = 0 # currently selected Figure
# Format:
# instance[self.n][0] = process
# instance[self.n][1] = terminal
def figure(number=None):
'''Make Gnuplot plot in a new Window or update a defined one figure(num=None, term='x11'):
>>> figure(2) # would create or update figure 2
>>> figure() # simply creates a new figure
returns the new figure number
'''
if not isinstance(number, int): # create new figure if no number was given
number = max(fl.instance) + 1
if number not in fl.instance: # number is new
proc = _Popen(['gnuplot', '-p'], shell=False, stdin=_PIPE, universal_newlines=True)
fl.instance[number] = [proc, default_term]
fl.n = number
c('set term ' + str(fl.instance[fl.n][1]) + ' ' + str(fl.n))
return number
def c(command):
'''
Send command to gnuplot
>>> c('plot sin(x)')
>>> c('plot "tmp.dat" u 1:2 w lp)
'''
proc = fl.instance[fl.n][0] # this is where the process is
proc.stdin.write(command + '\n') # \n 'send return in python 2.7'
proc.stdin.flush() # send the command in python 3.4+
def s(data, filename='tmp.dat'):
'''
saves numbers arrays and text into filename (default = 'tmp.dat)
(assumes equal sizes and 2D data sets)
>>> s(data, filename='tmp.dat') # overwrites/creates tmp.dat
'''
file = open(filename, 'w')
columns = len(data)
rows = len(data[0])
for j in range(rows):
for i in range(columns):
file.write(str(data[i][j]))
file.write(' ')
file.write('\n')
if j % 1000 == 0 :
file.flush() # write once after every 1000 entries
file.close() # write the rest
def plot(data, filename='tmp.dat'):
''' Save data into filename (default = 'tmp.dat') and send plot instructions to Gnuplot'''
s(data, filename)
c('plot "' + filename + '" w lp')
def p(filename='tmp.ps', width=14, height=9, fontsize=12, term=default_term):
'''Script to make gnuplot print into a postscript file
>>> p(filename='myfigure.ps') # overwrites/creates myfigure.ps
'''
c('set term postscript size ' + str(width) + 'cm, ' + str(height) + 'cm color solid ' +
str(fontsize) + " font 'Calibri';")
c('set out "' + filename + '";')
c('replot;')
c('set term ' + str(term) + '; replot')
def pdf(filename='tmp.pdf', width=14, height=9, fontsize=12, term=default_term):
'''Script to make gnuplot print into a pdf file
>>> pdf(filename='myfigure.pdf') # overwrites/creates myfigure.pdf
'''
c('set term pdf enhanced size ' + str(width) + 'cm, ' + str(height) + 'cm color solid fsize ' +
str(fontsize) + " fname 'Helvetica';")
c('set out "' + filename + '";')
c('replot;')
c('set term ' + str(term) + '; replot')
fl = _FigureList()
.. image:: https://badge.fury.io/py/PyGnuplot@2x.svg
:target: https://badge.fury.io/py/PyGnuplot
.. image:: https://anaconda.org/benschneider/pygnuplot/badges/version.svg
:target: https://anaconda.org/benschneider/pygnuplot
.. image:: https://travis-ci.org/benschneider/PyGnuplot.svg?branch=master
:target: https://travis-ci.org/benschneider/PyGnuplot
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
:target: https://github.com/benschneider/PyGnuplot/blob/master/LICENSE
PyGnuplot: Python wrapper for Gnuplot
-------------------------------------
Author: Ben Schneider
Requires:
.........
Gnuplot (http://www.gnuplot.info)
numpy
Installation:
.............
Using pip
.. code::
pip install PyGnuplot
Using conda
.. code::
conda install -c benschneider pygnuplot
Upgrade:
........
.. code::
pip install --upgrade PyGnuplot
Functions:
..........
**c(command)**
pipe a command to gnuplot as if in gnuplot command promt
.. code:: python
c('plot sin(x)')
**s(data, filename='tmp.dat')**
save arrays into file (filename = 'tmp.dat') easily read by Gnuplot
.. code:: python
s([X,Y,Z]) # creates tmp.dat
.. code:: python
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
.. code:: python
plot([x,y])
**figure(number=None, term='x11')**
Create a new or update a figure
.. code:: python
figure(1)
**p(filename='tmp.ps', width=14, height=9, fontsize=12, term='x11')**
Create postscript file (overwrites existing)
.. code:: python
p('myfile.ps')
**pdf(filename='tmp.pdf', width=14, height=9, fontsize=12, term='x11')**
Create a pdf file (overwrites existing)
.. code:: python
pdf('myfile.pdf')
Setup terminal
..............
Default terminal is 'x11' unless defined otherwise i.e. for windows:
.. code:: python
import PyGnuplot as gp
gp.default_term = 'wxt'
Examples:
.........
* 1 Example code
.. code:: python
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
.. code::
python example.py
+-----------------------------------------------------------------------------------------------------------------+
|.. figure:: https://cloud.githubusercontent.com/assets/4573907/17233530/e4be9342-5530-11e6-9c71-e812a2fb4000.png |
+-----------------------------------------------------------------------------------------------------------------+
import numpy as np
import PyGnuplot as pg
x = np.arange(1000)/20.0
y1 = x-25
y2 = y1*np.sin(x-25)
pg.s([x, y1, y2], filename='example.out') # save data into a file t.out
pg.c('set title "example.pdf"; set xlabel "x-axis"; set ylabel "y-axis"')
pg.c('set yrange [-25:25]; set key center top')
pg.c("plot 'example.out' u 1:2 w l t 'y=x-25") # plot fist part
pg.c("replot 'example.out' u 1:3 w l t 'y=(x-25)*sin(x-25)'")
pg.c("replot 'example.out' u 1:(-$2) w l t 'y=25-x'")
pg.pdf('example.pdf') # export figure into a pdf file
#!/bin/sh
python setup.py install
python setup.py install
[metadata]
description-file = 'README.rst'
setup.py 0 → 100644
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
with open('README.rst', 'r') as f:
long_description = f.read()
setup(name='PyGnuplot',
py_modules=['PyGnuplot'],
version='0.11.16',
license='MIT',
description='Python Gnuplot wrapper',
long_description=long_description,
author='Ben Schneider',
author_email=' ',
url='https://github.com/benschneider/PyGnuplot',
download_url='https://github.com/benschneider/PyGnuplot/archive/0.11.15.tar.gz',
keywords=['gnuplot', 'plot'],
# install_requires=['numpy'],
classifiers=["Topic :: Scientific/Engineering",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Development Status :: 4 - Beta"],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment