././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1664491813.207104 PyGnuplot-0.12.3/0000755000076500000240000000000014315420445014114 5ustar00benschneiderstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664477333.0 PyGnuplot-0.12.3/LICENSE0000644000076500000240000000206714315364225015131 0ustar00benschneiderstaffThe 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. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664477333.0 PyGnuplot-0.12.3/MANIFEST.in0000644000076500000240000000006614315364225015657 0ustar00benschneiderstaffinclude LICENSE include README.rst include example.py ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1664491813.2071466 PyGnuplot-0.12.3/PKG-INFO0000644000076500000240000001456414315420445015223 0ustar00benschneiderstaffMetadata-Version: 2.1 Name: PyGnuplot Version: 0.12.3 Summary: Python Gnuplot wrapper Home-page: https://github.com/benschneider/PyGnuplot Download-URL: https://github.com/benschneider/PyGnuplot/archive/0.12.3.tar.gz Author: Ben Schneider Author-email: License: MIT Keywords: gnuplot,plot Classifier: Topic :: Scientific/Engineering Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Development Status :: 4 - Beta License-File: LICENSE .. 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=experimental :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) Installation: ............. Using pip .. code:: pip install PyGnuplot Using conda .. code:: conda install -c benschneider pygnuplot Upgrade: ........ .. code:: pip install --upgrade PyGnuplot Basic Usage: ............ .. code:: from PyGnuplot import gp figure1 = gp() # Create a new figure handle figure2 = gp(r"C:\Program Files\gnuplot\bin\gnuplot.exe") # Can also specify which gnuplot to use figure1.a("plot sin(x)") figure2.a("plot cos(x)") pi = figure.a("print pi") Functions available with each figure: ..................................... **c(command)** pipe a command to gnuplot as if in gnuplot command promt .. code:: python c('plot sin(x)') **save(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') **a(command='', vtype=str, timeout=0.05)** asks gnuplot: it sends a command to gnuplot and returns its response This is paricularly handy when using gnuplots fitting features vtype can be used to change the return format timeout is the time to wait for a response .. code:: python a('print pi') # returns the value of pi .. code:: python a('print pi; print pi') # returns 2 times the value of pi **r(vtype=str, timeout=0.05)** reads the gnuplot return buffer until its empty **plot(data, filename='tmp.dat')** Plot some data. Sends plot instructions and the data to Gnuplot .. code:: python plot([x,y]) **plot_b(data, v1='d', v2='%double')** Similar to plot: Sends plot instructions and the data to Gnuplot However it sends them in binary format, which can be beneficial when the dealing with larger quanities of numbers **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') **quit()** Closes windows,then gnuplot, then the pipe Setup terminal .............. This script will use the same default terminal that gnuplot used (it reads the GPVAL_TERM value when gnuplot starts up) it can still be modified by the 'default_term' variable: .. code:: python from PyGnuplot import gp fig1 = gp() fig1.default_term = 'wxt' New features: ............. **fit2d(data, func='y(x)=a + b*x', via='a,b', limit=1e-9)** Quickly Fit a simple 2-D data set and return the fitting results. This uses the new ask function "a()" Here we gather the fitting info from gnuplot and: **fit(self, data, func='y(x)=a + b*x', via='a,b', limit=1e-9, filename='tmp.dat', wait=1)** Allows for sligtly more complex fitting, filename: stores data first into a temporary file default: tmp.dat wait: define a waiting time in sec for gnuplot to finish its fitting default: 1sec .. code:: python import numpy as np f1 = gp() x = np.linspace(0, 20, 1001) yn = np.random.randn(1001)/10 y = np.sin(x) data = [x, y+yn] func = 'y(x) = a + b*cos(x + c)' # define a fitting function here. (a, b, c), report = f1.fit2d(data, func, via='a,b,c', limit=1e-9) # sending in the data the function used to fit and the variables that are to be found. f1.save(data, "tmp.dat") f1.a('plot "tmp.dat" w lp') f1.a('replot y(x)') +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://user-images.githubusercontent.com/4573907/193154658-92513c20-ab3c-4b29-b487-d98b79d85942.png | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://user-images.githubusercontent.com/4573907/193154419-133761a1-3e2f-4c00-87d2-2c47b7da62c5.png | +-----------------------------------------------------------------------------------------------------------------+ Examples: ......... * 1 Example code .. code:: python from PyGnuplot import gp import numpy as np X = np.arange(10) Y = np.sin(X/(2*np.pi)) Z = Y**2.0 fig1 = gp() fig1.save([X,Y,Z]) fig1.c('plot "tmp.dat" u 1:2 w lp) fig1.c('replot "tmp.dat" u 1:3' w lp) fig1.p('myfigure.ps') * 2 Example file .. code:: python example.py +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://cloud.githubusercontent.com/assets/4573907/17233530/e4be9342-5530-11e6-9c71-e812a2fb4000.png | +-----------------------------------------------------------------------------------------------------------------+ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1664491813.2069917 PyGnuplot-0.12.3/PyGnuplot.egg-info/0000755000076500000240000000000014315420445017547 5ustar00benschneiderstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664491813.0 PyGnuplot-0.12.3/PyGnuplot.egg-info/PKG-INFO0000644000076500000240000001456414315420445020656 0ustar00benschneiderstaffMetadata-Version: 2.1 Name: PyGnuplot Version: 0.12.3 Summary: Python Gnuplot wrapper Home-page: https://github.com/benschneider/PyGnuplot Download-URL: https://github.com/benschneider/PyGnuplot/archive/0.12.3.tar.gz Author: Ben Schneider Author-email: License: MIT Keywords: gnuplot,plot Classifier: Topic :: Scientific/Engineering Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Development Status :: 4 - Beta License-File: LICENSE .. 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=experimental :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) Installation: ............. Using pip .. code:: pip install PyGnuplot Using conda .. code:: conda install -c benschneider pygnuplot Upgrade: ........ .. code:: pip install --upgrade PyGnuplot Basic Usage: ............ .. code:: from PyGnuplot import gp figure1 = gp() # Create a new figure handle figure2 = gp(r"C:\Program Files\gnuplot\bin\gnuplot.exe") # Can also specify which gnuplot to use figure1.a("plot sin(x)") figure2.a("plot cos(x)") pi = figure.a("print pi") Functions available with each figure: ..................................... **c(command)** pipe a command to gnuplot as if in gnuplot command promt .. code:: python c('plot sin(x)') **save(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') **a(command='', vtype=str, timeout=0.05)** asks gnuplot: it sends a command to gnuplot and returns its response This is paricularly handy when using gnuplots fitting features vtype can be used to change the return format timeout is the time to wait for a response .. code:: python a('print pi') # returns the value of pi .. code:: python a('print pi; print pi') # returns 2 times the value of pi **r(vtype=str, timeout=0.05)** reads the gnuplot return buffer until its empty **plot(data, filename='tmp.dat')** Plot some data. Sends plot instructions and the data to Gnuplot .. code:: python plot([x,y]) **plot_b(data, v1='d', v2='%double')** Similar to plot: Sends plot instructions and the data to Gnuplot However it sends them in binary format, which can be beneficial when the dealing with larger quanities of numbers **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') **quit()** Closes windows,then gnuplot, then the pipe Setup terminal .............. This script will use the same default terminal that gnuplot used (it reads the GPVAL_TERM value when gnuplot starts up) it can still be modified by the 'default_term' variable: .. code:: python from PyGnuplot import gp fig1 = gp() fig1.default_term = 'wxt' New features: ............. **fit2d(data, func='y(x)=a + b*x', via='a,b', limit=1e-9)** Quickly Fit a simple 2-D data set and return the fitting results. This uses the new ask function "a()" Here we gather the fitting info from gnuplot and: **fit(self, data, func='y(x)=a + b*x', via='a,b', limit=1e-9, filename='tmp.dat', wait=1)** Allows for sligtly more complex fitting, filename: stores data first into a temporary file default: tmp.dat wait: define a waiting time in sec for gnuplot to finish its fitting default: 1sec .. code:: python import numpy as np f1 = gp() x = np.linspace(0, 20, 1001) yn = np.random.randn(1001)/10 y = np.sin(x) data = [x, y+yn] func = 'y(x) = a + b*cos(x + c)' # define a fitting function here. (a, b, c), report = f1.fit2d(data, func, via='a,b,c', limit=1e-9) # sending in the data the function used to fit and the variables that are to be found. f1.save(data, "tmp.dat") f1.a('plot "tmp.dat" w lp') f1.a('replot y(x)') +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://user-images.githubusercontent.com/4573907/193154658-92513c20-ab3c-4b29-b487-d98b79d85942.png | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://user-images.githubusercontent.com/4573907/193154419-133761a1-3e2f-4c00-87d2-2c47b7da62c5.png | +-----------------------------------------------------------------------------------------------------------------+ Examples: ......... * 1 Example code .. code:: python from PyGnuplot import gp import numpy as np X = np.arange(10) Y = np.sin(X/(2*np.pi)) Z = Y**2.0 fig1 = gp() fig1.save([X,Y,Z]) fig1.c('plot "tmp.dat" u 1:2 w lp) fig1.c('replot "tmp.dat" u 1:3' w lp) fig1.p('myfigure.ps') * 2 Example file .. code:: python example.py +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://cloud.githubusercontent.com/assets/4573907/17233530/e4be9342-5530-11e6-9c71-e812a2fb4000.png | +-----------------------------------------------------------------------------------------------------------------+ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664491813.0 PyGnuplot-0.12.3/PyGnuplot.egg-info/SOURCES.txt0000644000076500000240000000031514315420445021432 0ustar00benschneiderstaffLICENSE MANIFEST.in PyGnuplot.py README.rst example.py setup.cfg setup.py PyGnuplot.egg-info/PKG-INFO PyGnuplot.egg-info/SOURCES.txt PyGnuplot.egg-info/dependency_links.txt PyGnuplot.egg-info/top_level.txt././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664491813.0 PyGnuplot-0.12.3/PyGnuplot.egg-info/dependency_links.txt0000644000076500000240000000000114315420445023615 0ustar00benschneiderstaff ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664491813.0 PyGnuplot-0.12.3/PyGnuplot.egg-info/top_level.txt0000644000076500000240000000001214315420445022272 0ustar00benschneiderstaffPyGnuplot ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664484052.0 PyGnuplot-0.12.3/PyGnuplot.py0000644000076500000240000002111714315401324016424 0ustar00benschneiderstaff ''' 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+ Special Thanks to ddip! This code was rewritten according to ddipp's suggestions resulting in a cleaner and better code and finnaly giving accesss to gnuplot returns thus allowing the use of the gnuplot fit function. Also thanks to all the others who commented gave inputs and suggestions. Example: from PyGnuplot import gp import numpy as np X = np.arange(10) Y = np.sin(X/(2*np.pi)) Z = Y**2.0 fig1 = gp() fig1.save([X,Y,Z]) # saves data into tmp.dat fig1.c('plot "tmp.dat" u 1:2 w lp) # send 'plot instructions to gnuplot' fig1.c('replot "tmp.dat" u 1:3' w lp) fig1.pdf('myfigure.pdf') # outputs pdf file ''' import sys from subprocess import PIPE, Popen from threading import Thread from time import sleep try: from queue import Queue, Empty # Python 3.x except ImportError: from Queue import Queue, Empty # Python 2.x ON_POSIX = 'posix' in sys.builtin_module_names class gp(object): """PyGnuplot object figure example: f1 = gp(r"C:\Program Files\gnuplot\bin\gnuplot.exe") pi = f1.a('print pi') """ def __init__(self, gnuplot_address='gnuplot'): # also also initialize with gnuplot_address = r"C:\Program Files\gnuplot\bin\gnuplot.exe" self.gnuplot_address=gnuplot_address ''' open pipe with gnuplot ''' self.p = Popen([gnuplot_address], stdin=PIPE, stderr=PIPE, stdout=PIPE, bufsize=1, close_fds=ON_POSIX, shell=False, universal_newlines=True) self.q_err = Queue() self.t_err = Thread(target=self.enqueue_std, args=(self.p.stderr, self.q_err)) self.t_err.daemon = True # thread dies with the program self.t_err.start() self.q_out = Queue() self.t_out = Thread(target=self.enqueue_std, args=(self.p.stdout, self.q_out)) self.t_out.daemon = True # thread dies with the program self.t_out.start() self.r() # clear return buffer self.default_term = str(*self.a('print GPVAL_TERM')) def enqueue_std(self, out, queue): ''' used to setup the queues for the return buffers''' for line in iter(out.readline, ''): queue.put(line) out.close() def c(self, command): ''' send a command to gnuplot. this does not check for responses >>> w('plot sin(x)') # only send a command to gnuplot''' self.p.stdin.write(command + '\n') # \n 'send return in python 2.7' self.p.stdin.flush() # send the command in python 3.4+ def r(self, vtype=str, timeout=0.05): ''' read line without blocking, also clears the buffer. >>> r() # read response from gnuplot''' lines = [] while True: try: line = self.q_err.get(timeout=timeout) # or .get_nowait() lines.append(vtype(line.strip())) except Empty: break return lines def a(self, command='', vtype=str, timeout=0.05): ''' ask gnuplot (write and get answer) >>> a('print pi') ''' self.c(command) sleep(0.01) # wait 10ms for gnuplot return self.r(vtype, timeout) def m_str(self, data, delimiter=' '): ''' turn data into string format this string format can be used when sending data to gnuplot usually via: plot "-" u 1:2 w lp''' xy = list(zip(*data)) ascii_st = '' for i in xy: for j in i: ascii_st += str(j) + delimiter ascii_st += '\n' return ascii_st def plot(self, data, com='plot "-" u 1:2 w lp'): ''' quick plot data in gnuplot it basically pipes the data to gnuplot and plots it default plot : com = "plot "-" u 1:2 w lp" ''' str_data = self.m_str(data) self.c(com) self.c(str_data+'e') # add end character to plot string return self.r() def fit(self, data, func='y(x)=a + b*x', via='a,b', limit=1e-9, filename='tmp.dat', wait=1): '''simple quick way to fit with gnuplot this fit function temporarily stores the data in a file. Inputs: func : fitting function y(x) or f(x,y) or ... via : space separated variables to fit data : data set to fit filename : location where it can temporarily store its data wait : timing in s on how long to wait for the fit results Outputs: fit results in same order as via is defined report generated by gnuplot ''' self.save(data, filename=filename) func_name = func.split('=')[0] self.c(func) # 'y(x)=a+b*x' self.c('set fit limit '+str(limit)) self.c('fit ' + func_name + ' "' + filename + '" via ' + via) sleep(wait) # wait until fitting is done report = self.a() # if no report is returned maybe increase the wait time here return self.get_variables(via), report def fit2d(self, data, func='y(x)=a + b*x', via='a,b', limit=1e-9): '''simple quick way to fit with gnuplot Inputs: func : fitting function y(x) or f(x,y) or ... via : space separated variables to fit data : data set to fit Outputs: fit results in same order as via is defined report generated by gnuplot ''' str_data = self.m_str(data) func_name = func.split('=')[0] self.c(func) # 'y(x)=a+b*x' self.c('set fit limit '+str(limit)) self.c('fit ' + func_name + ' "-" via ' + via) report = self.a(str_data+'e') return self.get_variables(via), report def get_variables(self, via): ''' returns values stored in gnuplot as given by via Inputs: via : for example via = 'a b c d e' Outputs: results in same order as via is given ''' vals = via.split(',') ret = [] for i in vals: r = self.a('print ' + i) try: r = float(r[0]) # hard coded conversion if possible except ValueError: pass ret.append(r) return ret def save(self, data, filename='tmp.dat', delimiter=' '): ''' 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 ''' with open(filename, 'w') as f: filestr = self.m_str(data, delimiter=delimiter) f.write(filestr) f.close() # write the rest and close def empty_plot(self): self.c('plot [][-1:1] 1/0 t""') def ps(self, filename='tmp.ps', width=14, height=9, fontsize=12): '''Script to make gnuplot print into a postscript file >>> ps(filename='myfigure.ps') # overwrites/creates myfigure.ps ''' self.c('set term postscript size ' + str(width) + 'cm, ' + str(height) + 'cm color solid ' + str(fontsize) + " font 'Calibri';") self.c('set out "' + filename + '";replot;') self.c('set term ' + self.default_term + ';replot') return self.r() def pdf(self, filename='tmp.pdf', width=8.8, height=6, fontscale=0.5): '''Script to make gnuplot print into a pdf file >>> pdf(filename='myfigure.pdf') # overwrites/creates myfigure.pdf ''' self.c('set term pdfcairo fontscale ' + str(fontscale) + 'size ' + str(width) + 'cm, ' + str(height) + "cm;") self.c('set out "' + filename + '";replot;') self.c('set term ' + self.default_term + '; replot') return self.r() # clear buffer def quit(self): aa = self.a('exit') # close gnuplot self.p.kill() # kill pipe return aa if __name__ == '__main__': # test functionality import numpy as np f1 = gp() x = np.linspace(0, 20, 1001) yn = np.random.randn(1001)/10 y = np.sin(x) data = [x, y+yn] func = 'y(x) = a + b*cos(x + c)' (a, b, c), report = f1.fit(data, func, via='a,b,c', limit=1e-9) f1.save(data, "tmp.dat") f1.a('plot "tmp.dat" w lp') f1.a('replot y(x)') dat_s = f1.m_str([x, y], delimiter='\t') print() print("fitting function is: " + func) print("fit report:") for line in report: print(line) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664491792.0 PyGnuplot-0.12.3/README.rst0000644000076500000240000001303714315420420015600 0ustar00benschneiderstaff.. 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=experimental :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) Installation: ............. Using pip .. code:: pip install PyGnuplot Using conda .. code:: conda install -c benschneider pygnuplot Upgrade: ........ .. code:: pip install --upgrade PyGnuplot Basic Usage: ............ .. code:: from PyGnuplot import gp figure1 = gp() # Create a new figure handle figure2 = gp(r"C:\Program Files\gnuplot\bin\gnuplot.exe") # Can also specify which gnuplot to use figure1.a("plot sin(x)") figure2.a("plot cos(x)") pi = figure.a("print pi") Functions available with each figure: ..................................... **c(command)** pipe a command to gnuplot as if in gnuplot command promt .. code:: python c('plot sin(x)') **save(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') **a(command='', vtype=str, timeout=0.05)** asks gnuplot: it sends a command to gnuplot and returns its response This is paricularly handy when using gnuplots fitting features vtype can be used to change the return format timeout is the time to wait for a response .. code:: python a('print pi') # returns the value of pi .. code:: python a('print pi; print pi') # returns 2 times the value of pi **r(vtype=str, timeout=0.05)** reads the gnuplot return buffer until its empty **plot(data, filename='tmp.dat')** Plot some data. Sends plot instructions and the data to Gnuplot .. code:: python plot([x,y]) **plot_b(data, v1='d', v2='%double')** Similar to plot: Sends plot instructions and the data to Gnuplot However it sends them in binary format, which can be beneficial when the dealing with larger quanities of numbers **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') **quit()** Closes windows,then gnuplot, then the pipe Setup terminal .............. This script will use the same default terminal that gnuplot used (it reads the GPVAL_TERM value when gnuplot starts up) it can still be modified by the 'default_term' variable: .. code:: python from PyGnuplot import gp fig1 = gp() fig1.default_term = 'wxt' New features: ............. **fit2d(data, func='y(x)=a + b*x', via='a,b', limit=1e-9)** Quickly Fit a simple 2-D data set and return the fitting results. This uses the new ask function "a()" Here we gather the fitting info from gnuplot and: **fit(self, data, func='y(x)=a + b*x', via='a,b', limit=1e-9, filename='tmp.dat', wait=1)** Allows for sligtly more complex fitting, filename: stores data first into a temporary file default: tmp.dat wait: define a waiting time in sec for gnuplot to finish its fitting default: 1sec .. code:: python import numpy as np f1 = gp() x = np.linspace(0, 20, 1001) yn = np.random.randn(1001)/10 y = np.sin(x) data = [x, y+yn] func = 'y(x) = a + b*cos(x + c)' # define a fitting function here. (a, b, c), report = f1.fit2d(data, func, via='a,b,c', limit=1e-9) # sending in the data the function used to fit and the variables that are to be found. f1.save(data, "tmp.dat") f1.a('plot "tmp.dat" w lp') f1.a('replot y(x)') +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://user-images.githubusercontent.com/4573907/193154658-92513c20-ab3c-4b29-b487-d98b79d85942.png | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://user-images.githubusercontent.com/4573907/193154419-133761a1-3e2f-4c00-87d2-2c47b7da62c5.png | +-----------------------------------------------------------------------------------------------------------------+ Examples: ......... * 1 Example code .. code:: python from PyGnuplot import gp import numpy as np X = np.arange(10) Y = np.sin(X/(2*np.pi)) Z = Y**2.0 fig1 = gp() fig1.save([X,Y,Z]) fig1.c('plot "tmp.dat" u 1:2 w lp) fig1.c('replot "tmp.dat" u 1:3' w lp) fig1.p('myfigure.ps') * 2 Example file .. code:: python example.py +-----------------------------------------------------------------------------------------------------------------+ |.. figure:: https://cloud.githubusercontent.com/assets/4573907/17233530/e4be9342-5530-11e6-9c71-e812a2fb4000.png | +-----------------------------------------------------------------------------------------------------------------+ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664480435.0 PyGnuplot-0.12.3/example.py0000644000076500000240000000136114315372263016126 0ustar00benschneiderstafffrom PyGnuplot import gp f1 = gp() e = 2.718281828459045 def sin(x): ''' returns sin for each x ''' return (e**(i*1j)).imag x = list(range(1000)) x = [i/20 for i in x] # x = x/20 y1 = [i-25 for i in x] # y1 = x-25 y2 = [] # calculate y2 = y1*sin(y1) for i, j1 in enumerate(y1): y2.append(j1*sin(j1)) f1.s([x, y1, y2], filename='example.out') # save data into a file t.out f1.c('set title "example.pdf"; set xlabel "x-axis"; set ylabel "y-axis"') f1.c('set yrange [-25:25]; set key center top') f1.c("plot 'example.out' u 1:2 w l t 'y=x-25") # plot fist part f1.c("replot 'example.out' u 1:3 w l t 'y=(x-25)*sin(x-25)'") f1.c("replot 'example.out' u 1:(-$2) w l t 'y=25-x'") f1.pdf('example.pdf') # export figure into a pdf file ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1664491813.2072988 PyGnuplot-0.12.3/setup.cfg0000644000076500000240000000012214315420445015730 0ustar00benschneiderstaff[metadata] description-file = 'README.rst' [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1664487102.0 PyGnuplot-0.12.3/setup.py0000644000076500000240000000232714315407276015641 0ustar00benschneiderstafftry: 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.12.3', 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.12.3.tar.gz', keywords=['gnuplot', 'plot'], classifiers=["Topic :: Scientific/Engineering", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Development Status :: 4 - Beta"], )