python2-biggles-1.6.6/0000755000175100017510000000000011357716714013573 5ustar noltanoltapython2-biggles-1.6.6/PKG-INFO0000644000175100017510000000104711357716714014672 0ustar noltanoltaMetadata-Version: 1.0 Name: python2-biggles Version: 1.6.6 Summary: scientific plotting module Home-page: http://biggles.sourceforge.net/ Author: Mike Nolta Author-email: mike@nolta.net License: GPL Description: Biggles is a Python module for creating publication-quality 2D scientific plots. It supports multiple output formats (postscript, x11, png, svg, gif), understands simple TeX, and sports a high-level, elegant interface. It's intended for technical users with sophisticated plotting needs. Platform: UNKNOWN python2-biggles-1.6.6/make.rules0000644000175100017510000000173010663440633015556 0ustar noltanolta# # $Id: make.rules,v 1.2 2007/08/24 02:25:31 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # .PHONY: all clean all: $(TARGETS) clean: -rm *.so %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< %.so: %.o $(CCSHARED) -o $@ $^ $(LDFLAGS) python2-biggles-1.6.6/MANIFEST.in0000644000175100017510000000216507660017162015326 0ustar noltanolta# # $Id: MANIFEST.in,v 1.7 2003/05/12 22:21:38 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # include ChangeLog COPYING CREDITS INSTALL README* TODO include make.* Makefile src/Makefile src/libplot/Makefile include src/Makefile.win src/libplot/Makefile.win src/libplot/libplotexports.def include *.spec MANIFEST.in include src/config.ini recursive-include examples *.py recursive-include src *.pyc python2-biggles-1.6.6/INSTALL0000644000175100017510000000307710611710021014604 0ustar noltanolta Prerequistites -------------- 1. Python Available at . 2. Numeric Python Available at . Be careful which version you install; newer versions tend to support only the most recent Python release. 3. GNU plotutils package Available at . After installing, you need to make sure biggles can find libplot.so. On most systems adding $(prefix)/lib to LD_LIBRARY_PATH will work, where $(prefix) is the directory plotutils was installed in (usually /usr/local). Distutils Installation ---------------------- If you're running Python 2.0 or greater, or have Distutils installed, you can install biggles using the setup.py file. Try: $ cd python-biggles-x.y.z/ $ python setup.py build_ext -I/path/to/libplot/include $ python setup.py install See the distutils documentation for more information. Makefile Installation --------------------- If you don't want to install using Distutils, you can use the Makefile provided. On most systems running: $ cd python-biggles-x.y.z/ $ gmake $ gmake install will work. The PYTHON variable in make.inc should be set to the command you use to start the python interpreter (defaults to "python"). The directory the Makefile chooses to install the module is based on information from the python sys module, which you can override by changing PYSITEPKGS. If the libplot library is not installed under /usr/local, and you installed it from source, edit the "LIBPLOT_PREFIX" line in make.inc to point to the right directory. python2-biggles-1.6.6/Makefile0000644000175100017510000000321507371054401015221 0ustar noltanolta# # $Id: Makefile,v 1.11 2001/11/03 20:52:17 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # include make.inc SRCDIR = ./src EXAMPLESDIR = ./examples .PHONY: all install uninstall clean all: cd $(SRCDIR) && $(MAKE) all cd $(SRCDIR)/libplot && $(MAKE) all install: all [ -d $(BIGGLESDIR) ] || mkdir -m755 $(BIGGLESDIR) install -m644 $(SRCDIR)/*.ini $(BIGGLESDIR) install -m644 $(SRCDIR)/*.py $(BIGGLESDIR) install -m644 $(SRCDIR)/*.pyc $(BIGGLESDIR) install -m755 $(SRCDIR)/*.so $(BIGGLESDIR) [ -d $(BIGGLESDIR)/libplot ] || mkdir -m755 $(BIGGLESDIR)/libplot install -m644 $(SRCDIR)/libplot/*.py $(BIGGLESDIR)/libplot install -m644 $(SRCDIR)/libplot/*.pyc $(BIGGLESDIR)/libplot install -m755 $(SRCDIR)/libplot/*.so $(BIGGLESDIR)/libplot uninstall: [ -d $(BIGGLESDIR) ] && rm -rf $(BIGGLESDIR) clean: cd $(SRCDIR) && $(MAKE) clean cd $(SRCDIR)/libplot && $(MAKE) clean -cd $(EXAMPLESDIR) && rm *.png *.eps python2-biggles-1.6.6/README.win0000644000175100017510000000542307554425066015254 0ustar noltanoltaBuilding Biggles for Microsoft Visual C++ ----------------------------------------- Prerequisites: - Set the PYTHONHOME environment variable if not already set (e.g. C:\Python22) - Install the Numerical Python (NumPy) package, if not already installed. - Make sure the NUMPYDIR and PLOTUTILDIR macros in libplot\Makefile.win are set correctly. - Get the necessary files for the build: Main folder: _biggles.c libplot subfolder: libplot.c plot.h libplotexports.def The *.c files can be found in the Biggles distribution. plot.h can be obtained from the Biggles CVS archive (if not in newer source distributions). libplotexports.def should be included with the Biggles Win32 Makefiles. If not, it can be generated using DUMPBIN /exports on libplot.dll. Building: - Build both _biggles.pyd and libplot.pyd by running the main Makefile (not the one in the libplot folder). nmake -f Makefile.win - The Makefile will generate a libplotexports.lib import library for libplot. If you happen to have one you're particularly fond of, modify the Makefile to use it instead. - See the comments in the individual Makefiles for details on how to build the pieces separately (if desired). Preparing for Use: - As described on the Biggles installation page, you will need these three DLLs: libplot.dll (tested version from plotutils-2.4.1-1-bin.zip) libpng.dll (tested version from libpng-1.0.12-bin.zip) zlib.dll (tested version from zlib-1.1.3-bin.zip) - Care must be taken where the files are located because libplot.dll and libplot.pyd have the same base name. Python must find libplot.pyd on the PYTHONPATH before it finds libplot.dll and these must be found before the scripts (as I understand it). The way I have found least messy is to put all the .dll and .pyd files in the %PYTHONHOME%\DLLs folder and then add this to your PYTHONPATH before the location of the script files. If the Biggles scripts are in the %PYTHONHOME%\Lib\site-packages\biggles folder, the your PYTHONPATH environment variable should have the following two entries in the given order: %PYTHONHOME%\DLLs;%PYTHONHOME%\Lib\site-packages These two entries don't have to be back-to-back like this, just in this order. Don't rely on these being set from the registry or path configuration files (.pth) as the order may change when other modules are installed or removed. Notes: - This has only been tested on Windows XP with Microsoft Visual C++ 6 and Python 2.2.1 but will likely work on many other combinations. python2-biggles-1.6.6/make.inc0000644000175100017510000000357111357712020015173 0ustar noltanolta# # $Id: make.inc,v 1.9 2010/04/09 20:50:18 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # PYTHON = python CC = gcc CCSHARED = gcc -shared CFLAGS = -Wall -O2 -fPIC OS = $(shell uname) ## compile flags for the libplot library (part of GNU plotutils) LIBPLOT_PREFIX = /usr LIBPLOT_CPPFLAGS = -I$(LIBPLOT_PREFIX)/include LIBPLOT_LDFLAGS = -L$(LIBPLOT_PREFIX)/lib64 -L$(LIBPLOT_PREFIX)/lib \ -lplot -L/usr/X11R6/lib64 -L/usr/X11R6/lib \ -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 NUMPY_CPPFLAGS = -I$(shell $(PYTHON) -c 'import numpy; print numpy.get_include()') ## these options probably don't need to be changed PYPREFIX = $(shell $(PYTHON) -c 'import sys; print sys.prefix') PYVERSION = $(shell $(PYTHON) -c 'import sys; print sys.version[:3]') PYINCLUDE = $(PYPREFIX)/include/python$(PYVERSION) PYSITEPKGS = $(PYPREFIX)/lib/python$(PYVERSION)/site-packages BIGGLESDIR = $(PYSITEPKGS)/biggles BASE_CPPFLAGS = -I$(PYINCLUDE) BASE_LDFLAGS = -lm ifeq ($(OS),Darwin) CCSHARED = gcc -undefined dynamic_lookup BASE_LDFLAGS = -Wl,-F. -bundle -L$(PYPREFIX)/lib -lpng ifneq (,$(findstring Framework,$(PYPREFIX))) BASE_LDFLAGS += -framework Python endif endif python2-biggles-1.6.6/ChangeLog0000644000175100017510000001667311357715504015356 0ustar noltanolta 1.6.6 (27 Nov 2008) -------------------- * Fixed issue that caused all images to be 570x570 on some systems, due to a change in the python2.5 C API. * Improved setup.py and Makefiles. * Contours can now be used with PlotKey. * Added Labels component. Similar to Points, but with text labels instead of symbols. 1.6.5 (20 Mar 2007) ------------------- * Replaced Numeric with numpy. 1.6.4 (08 Mar 2004) ------------------- * Phil Kromer contributed the new ColoredPoints and Density components. See example9.py for details. * Todd Fox contributed Makefiles for building with MS Visual C++. * Can now specify the width/height of postscript output, by passing (e.g.) width="5in" or height="10in" to the functions which produce postscript output. Default values are in the [postscript] section of config.ini. The old [printer]/paper option is now [postscript]/paper. * Added UpperLimits, LowerLimits components. These produce symbols with half-arrows indicating the true value is below/above the point. * Added TeX codes \`,\',\^,\",\~ for character accents. 1.6.3 (16 Jul 2002) ------------------- * Mike Romberg fixed bugs related to packaging biggles with imputil. 1.6.2 (23 May 2002) ------------------- * Spiros Papadimitriou contributed an experimental piddle port. * You can now specify partial ranges for plots. So "p.xrange = 2, None" will set the lower bound of the plot p to be 2, and the upper bound will be guessed from the data contained in the plot. * Replaced "!= None" with "is not None" everywhere. * Fixed bug with added space in scientific notation ticklabels. 1.6.1 (14 Nov 2001) ------------------- * Martin Lamar ported the code to Windows. * Replaced "== None" with "is None" everywhere (again thanks to Martin). This should fix crashes with recent versions of numpy. 1.6.0 (07 Nov 2001) ------------------- * Clipping! * Better performance for plots with lots of data. Parts of the code were vectorized, and a new integrated libplot interface was written. Biggles no longer uses the python-libplot module. * Jamie Mazer contributed code for Matlab emulation, accessible by "import biggles.matlab". * Added the multipage() function for multipage postscript output. Thanks to Olivier Andrieu for the original patch. * Changed the default plot window size to 512x512 from 570x570. * Bug fixes: better tick generation on huge-ranged log axes; the "thousand tiny lines" problem with contour plots. 1.5.0 (31 Aug 2001) ------------------- * Completely rewrote FramedPlot. Fully backward compatible with the old FramedPlot, it adds a tremendous number of new features. CustomFramedPlot is now deprecated. * Configuration options are now read when objects are instantiated, instead of during class definition. This means you can change them in the middle of a script, using the new configure() function. * Added read_rows(),read_matrix() functions. They read text data files, returning a list of rows and a matrix, respectively. Numeric Python arrays are returned by default. The readcolumn() function has been renamed read_column(). * TeX font control sequences \it and \bf are now recognized. Spaces are no longer ignored during math mode. * You can now specify single characters as plotting symbols. * Added DataBox/PlotBox components. * Added .align_interiors option to Table. * Added .drop_to_zero option to Histogram. * Added .title_style attribute to all containers. * The container methods .save_as_XXX() were renamed .write_XXX(). While the old names are not deprecated, they will no longer appear in the documentation. * Bug fixes: fixed crash when used by a CGI script, dropped minus sign for axis labels which are powers of ten, compile problem on Suns. 1.4.0 (06 Mar 2001) ------------------- * Biggles now requires the Numeric Python module, and is no longer a pure Python module. * Added support for contour plots with new Contours() component. * HammerAitoffPlot(): new & improved geodesic algorithm; added support for rotated coordinates. * Added FillAbove(), FillBelow() components. Fill*() objects now work with PlotKey(). * More robust interactive session detection. The config.ini option "[screen] guess_interactive" has been renamed "persistent". Removed interactive() function. * Better tick guesses for log axes. * Bug fixes: apparent data scaling by FramedArray when aspect_ratio is set; several related to calculating limits. 1.3.0 (17 Dec 2000) ------------------- * Breaks old Table cell{spacing,padding} values; multipying them by 100 should work in most cases. * Renamed Label{Data,Plot} -> {Data,Plot}Label, LineSlope -> Slope, and ErrorEllipses -> Ellipses. The old names still work but are deprecated. * {Line,Symbol}Key have been superceded by PlotKey and are now deprecated. * New plot type: CustomFramedPlot(). Similar to FramedPlot(), but allows finer control over the frame style. * New plot type: HammerAitoffPlot(). An equal-area projection of the sphere, Hammer-Aitoff plots are commonly used in astrophysics. * New FramedArray options: .uniform_limits & .cellspacing. * New components: Circle(s), Ellipse, Geodesic, Point, PlotInset, and PlotLine. * You can now specify a minimum fontsize with "fontsize_min" in config.ini. * Various speed improvements, bug fixes, and infrastructure work. 1.2.1 (31 Oct 2000) ------------------- * Reorganized config.ini file. * The readcolumn() function can be configured to return Numeric arrays. * Added interactive() function to let users control X window behavior. * Fixed a couple of axis bugs triggered by very large limits. 1.2.0 (09 Oct 2000) ------------------- * Added distutils setup.py file. [contributed by Berthold Hllmann] * Added FramedArray container for grouping similar plots. * Added SymmetricErrorBars[XY] helper functions. * You can now say "t[i,j]=x" instead of "t.set(i,j,x)" for Table objects. * Broke readcolumn() so users can pass in their own string -> number conversion functions. Also, readcolumn now ignores blank lines and those starting with a comment character. * When used interactively, biggles now reuses the same X window insteading of creating a new window each time .show() is called. * Fixed stupid printing bug. 1.1.0 (22 Sep 2000) ------------------- * LineKey, SymbolKey, and Inset now take plot coordinates instead of data coordinates. Plot coordinates run from 0 -> 1 for each axis. Sorry about the breakage. * Inset coordinates now specify the frame location, not the bounding box. More breakage. * Replaced Label with LabelData & LabelPlot. LabelData works the same as Label, and LabelPlot takes plot coordinates instead of data coordinates. * Added LineSlope, Line[XY] components. * Added readcolumn() function. Returns a list of column values from a flat ASCII file. * More namespace cleanup. 1.0.3 (02 Sep 2000) ------------------- * Fixed a couple of layout bugs. Handling of large tables and elongated plots is greatly improved. [thanks to Jamie Mazer] * .save_as_{eps,img}() now recognize the filename "-" as stdout. * Better log ticks. * Namespace cleanup. 1.0.2 (18 Aug 2000) ------------------- * Top level layout overhauled. Ugly-hack-that-sorta-worked replaced with Elegant Solution. Naturally, it's quite a bit slower. * Added "cellpadding" and "cellspacing" to Table, similar to HTML tables. 1.0.1 (14 Aug 2000) ------------------- * Prettier tick labels. * Fixed stupid aspect_ratio bug. 1.0.0 (12 Aug 2000) ------------------- * First stable release. python2-biggles-1.6.6/TODO0000644000175100017510000000010107660017162014244 0ustar noltanolta * barcharts * time axes * reversed axes; i.e. p.xrange=[1,0] python2-biggles-1.6.6/README0000644000175100017510000000245607370331470014452 0ustar noltanolta Biggles : Scientific Plotting with/in/for Python ------------------------------------------------ Biggles is a Python module for creating publication-quality 2D scientific plots. It supports multiple output formats (postscript, x11, png, svg, gif), understands simple TeX, and sports a high-level, elegant interface. It's intended for technical users with sophisticated plotting needs. The goal is to produce a plotting package that isn't deeply frustrating. Simple Example -------------- Here's a simple biggles script: #!/usr/bin/env python import biggles x = [1, 2, 3, 4, 5] y = [5, 4, 3, 2, 1] p = biggles.FramedPlot() p.add( biggles.Curve(x, y) ) p.show() This produces an X window with a framed plot of the curve y(x). You can find more in the 'examples/' directory included with the source distribution. More Information ---------------- Complete documentaion is available at the biggles website: http://biggles.sourceforge.net/ If you'd like to receive announcements of new biggles releases, subscribe to the biggles-announce mailing list: http://lists.sourceforge.net/mailman/listinfo/biggles-announce Questions about biggles usage should be send to: biggles-help@lists.sourceforge.net Bug reports, feature requests, and patches should be sent to: biggles-devel@lists.sourceforge.net python2-biggles-1.6.6/setup.py0000644000175100017510000001344011357715757015315 0ustar noltanolta#!/usr/bin/env python # # $Id: setup.py,v 1.34 2010/04/09 21:28:15 mrnolta Exp $ # # Copyright (C) 2001-10 : # # Berthold Hollmann # Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # # distutils setup file for biggles originally contributed # by Berthold Hollmann. # from distutils.core import setup, Extension from distutils.command.install_data import install_data from distutils.sysconfig import get_python_inc import distutils.log import sys, os, os.path # include/library directories # if None, setup will try to discover the correct value automatically plot_h_dir = None # dir containing plot.h (from plotutils) libplot_dir = None # dir containing libplot.so (from plotutils) libX11_dir = None # dir containing libX11.so def search_for_file( name, dirs ): for dir in dirs: if not os.path.isdir( dir ): continue fn = os.path.join( dir, name ) if os.path.exists(fn): return dir #print "%s not found" % name return None def search_for_library( name, dirs ): extns = ['a','so','dylib'] for extn in extns: dir = search_for_file( 'lib'+name+'.'+extn, dirs ) if dir is not None: return dir #print "lib%s not found" % name return None def dir_ends_in( dir, x ): # returns True is dir is of the form "/../../x" head,tail = os.path.split( dir ) if tail == '': head,tail = os.path.split( head ) if tail == x: return True return False _biggles_module_inc_dirs = [] libplot_module_inc_dirs = [] libplot_module_lib_dirs = [] if sys.platform == "win32": libplot_module_libs = ["plot.dll"] else: try: import numpy numpy_inc_dir = numpy.get_include() _biggles_module_inc_dirs.append( numpy_inc_dir ) libplot_module_inc_dirs.append( numpy_inc_dir ) except: print "numpy module not found; add /path/to/numpy to PYTHONPATH" candidate_dirs = [ '/usr', '/usr/X11R6', sys.prefix, ] if 'LD_LIBRARY_PATH' in os.environ: for dir in os.environ['LD_LIBRARY_PATH'].split(':'): head,tail = os.path.split( dir ) if tail == '': head,tail = os.path.split( head ) if tail == 'lib' or tail == 'lib64': candidate_dirs.append( head ) candidate_dirs.append( '/usr/local' ) candidate_lib_dirs = [] for dir in candidate_dirs: candidate_lib_dirs.append( os.path.join(dir,'lib') ) candidate_lib_dirs.append( os.path.join(dir,'lib64') ) candidate_inc_dirs = [] for dir in candidate_dirs: candidate_inc_dirs.append( os.path.join(dir,'include') ) if plot_h_dir is None: plot_h_dir = search_for_file( 'plot.h', candidate_inc_dirs ) print "found plot.h in %s" % plot_h_dir if libplot_dir is None: libplot_dir = search_for_library( 'plot', candidate_lib_dirs ) print "found libplot in %s" % libplot_dir if libX11_dir is None: libX11_dir = search_for_library( 'X11', candidate_lib_dirs ) print "found libX11 in %s" % libX11_dir if plot_h_dir is not None: libplot_module_inc_dirs.append( plot_h_dir ) else: print 'unable to find plot.h; add "-I/path/to/plot.h"' if libplot_dir is not None: libplot_module_lib_dirs.append( libplot_dir ) else: print 'unable to find libplot; add "-L/path/to/libplot"' if libX11_dir is not None: libplot_module_lib_dirs.append( libX11_dir ) else: print 'unable to find plot.h; add "-L/path/to/libX11"' #_biggles_module_inc_dirs = [ numpy_inc_dir ] #libplot_module_inc_dirs = [ plot_h_dir, numpy_inc_dir ] #libplot_module_lib_dirs = [ libplot_dir, libX11_dir ] libplot_module_libs = ["plot","Xaw","Xmu","Xt","SM","ICE","Xext","X11"] # own install_data class to allow installation of data file # (config.ini) to biggles directory class my_install_data( install_data ): def finalize_options( self ): self.set_undefined_options( "install", \ ( "install_lib", "install_dir" ), \ ( "root", "root" ), \ ( "force", "force" ), \ ) long_description = """\ Biggles is a Python module for creating publication-quality 2D scientific plots. It supports multiple output formats (postscript, x11, png, svg, gif), understands simple TeX, and sports a high-level, elegant interface. It's intended for technical users with sophisticated plotting needs. """ setup( # Distribution meta-data name = "python2-biggles", version = "1.6.6", author = "Mike Nolta", author_email = "mike@nolta.net", url = "http://biggles.sourceforge.net/", license = "GPL", description = "scientific plotting module", long_description= long_description, # Description of the modules and packages in the distribution packages = [ "biggles", "biggles.libplot" ], package_dir = { "biggles" : "src" }, ext_package = "biggles", ext_modules = [ Extension( "_biggles", ["src/_biggles.c"], include_dirs = _biggles_module_inc_dirs ), Extension( "libplot.libplot", ["src/libplot/libplot.c"], include_dirs = libplot_module_inc_dirs, library_dirs = libplot_module_lib_dirs, libraries = libplot_module_libs ), ], cmdclass = { "install_data" : my_install_data }, data_files = [ ("biggles", ["src/config.ini"]) ] ) # vim: sts=8 sw=8 noexpandtab python2-biggles-1.6.6/setup.cfg0000644000175100017510000000305607370404153015407 0ustar noltanolta# # $Id: setup.cfg,v 1.3 2001/11/02 02:43:55 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # [bdist_rpm] python = python2 release = 1 packager = Mike Nolta requires = plotutils python2 group = Applications/Graphics doc_files = ChangeLog COPYING CREDITS INSTALL README README.debian examples/ changelog = * Wed Oct 31 2001 Mike Nolta - Now using distutils to make rpms for python2. * Fri Oct 26 2001 Michael Nolta - Updated for new file layout. Added *.pyo files. * Sun Jan 25 2001 Michael Nolta - Added support for *.so files. * Sun Dec 17 2000 Michael Nolta - Added *.pyc files. * Tue Nov 24 2000 Michael Nolta - Created. python2-biggles-1.6.6/COPYING0000644000175100017510000004312707130205532014616 0ustar noltanolta GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. python2-biggles-1.6.6/CREDITS0000644000175100017510000000227507660005313014605 0ustar noltanolta Written By: * Mike Nolta Contributors: * Walter Brisken lots of testing and suggestions HammerAitoff plots * Berthold Hllmann setup.py file * Phil Kromer ColoredPoints, DensityPlot * Jamie Mazer matlab emulation * Martin Lamar windows patches, installer, and instructions * Spiros Papadimitriou port to piddle * Tavis Rudd latex doc skeleton * Todd Fox makefiles and readme for windows Bug Reports, Ideas, Patches: * Alexander Wissner-Gross * Antti Honkela * Chad Netzer * Evelyn Mitchell * Herb Schilling * Kurt Riedel * Mark Coletti * Michele De la Pena * Mike Romberg * Olivier Andrieu * Robert Kern * Rob Lowrie * SungPil Yoon python2-biggles-1.6.6/examples/0000755000175100017510000000000011357716714015411 5ustar noltanoltapython2-biggles-1.6.6/examples/example8.py0000755000175100017510000000307310611710021017465 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import numpy # # Create example 2-dimensional data set of two solitons colliding. # n = 64 x = numpy.arange( -10., 10., 20./n ) t = numpy.arange( -1., 1., 2./n ) z = numpy.zeros( (len(x),len(t)) ) for i in range(len(x)): for j in range(len(t)): z[i,j] = -12. * (3. + 4.*numpy.cosh(2.*x[i]-8.*t[j]) \ + numpy.cosh(4.*x[i] - 64.*t[j])) / \ (3.*numpy.cosh(x[i]-28.*t[j]) \ + numpy.cosh(3.*x[i]-36.*t[j]))**2 # # Make contour component. # c = biggles.Contours( z, x, t, color="red" ) # # For fine-grained color control, the Contours component allows you to # specify a function which returns the color applied to each contour line. # The arguments passed to the function are: # # i integer index of contour (0,..,n-1) # n total number of contours # z0 z value of contour # z_min minimum z contour value # z_max maximum z contour value # # The function should return a valid color, or None for the default. # # Here we show how to set every other contour to blue. The remaining # contours are drawn with the default color, defined above to be red. # def even_blue( i, n, z0, z_min, z_max ): if i % 2 == 0: return 0x0000ff return None c.func_color = even_blue # # Similarly, Contours accepts similar functions for line type (.func_linestyle) # and width (.func_linewidth). The arguments passed are the same. # # # Make framed plot container and add contour component. # p = biggles.FramedPlot() p.add( c ) # # Output. # #p.write_img( 400, 400, "example8.png" ) #p.write_eps( "example8.eps" ) p.show() python2-biggles-1.6.6/examples/example1.py0000755000175100017510000000072311357716476017511 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import numpy, math x = numpy.arange( 0, 3*math.pi, math.pi/30 ) c = numpy.cos(x) s = numpy.sin(x) p = biggles.FramedPlot() p.title = "title" p.xlabel = r"$x$" p.ylabel = r"$\Theta$" p.add( biggles.FillBetween(x, c, x, s) ) p.add( biggles.Curve(x, c, color="red") ) p.add( biggles.Curve(x, s, color="blue") ) #p.write_img( 400, 400, "example1.png" ) #p.write_eps( "example1.eps" ) p.show() python2-biggles-1.6.6/examples/example7.py0000755000175100017510000000076607660005320017503 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import string err_msg = """ This example needs the following data file: http://biggles.sourceforge.net/data/continents """ try: m = biggles.read_rows( "continents" ) except IOError: print err_msg sys.exit(-1) p = biggles.HammerAitoffPlot() p.ribs_l = 2 for i in range(len(m)/2): l = m[2*i] b = m[2*i+1] p.add( biggles.Curve(l, b) ) #p.write_img( 400, 400, "example7.png" ) #p.write_eps( "example7.eps" ) p.show() python2-biggles-1.6.6/examples/example6.py0000755000175100017510000000121710611710021017461 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import numpy, math x = numpy.arange( 1*math.pi, 3*math.pi, math.pi/30 ) c = numpy.cos(x) s = numpy.sin(x) p = biggles.FramedPlot() p.aspect_ratio = 1 p.frame1.draw_grid = 1 p.frame1.tickdir = 1 p.x1.label = "bottom" p.x1.subticks = 1 p.y1.label = "left" p.y1.draw_spine = 0 p.x2.label = "top" p.x2.range = 10, 1000 p.x2.log = 1 p.y2.label = "right" p.y2.draw_ticks = 0 p.y2.ticklabels = [ "-1", "-1/2", "0", "1/2", "1" ] p.add( biggles.Curve(x, c, type='dash') ) p.add( biggles.Curve(x, s) ) #p.write_img( 400, 400, "example6.png" ) #p.write_eps( "example6.eps" ) p.show() python2-biggles-1.6.6/examples/example2.py0000755000175100017510000000122410611710021017453 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import numpy import numpy.random p = biggles.FramedPlot() p.xrange = 0, 100 p.yrange = 0, 100 p.aspect_ratio = 1 x = numpy.arange( 0, 100, 5 ) yA = numpy.random.normal( 40, 10, (len(x),) ) yB = x + numpy.random.normal( 0, 5, (len(x),) ) a = biggles.Points( x, yA, type="circle" ) a.label = "a points" b = biggles.Points( x, yB ) b.label = "b points" b.style( type="filled circle" ) l = biggles.Slope( 1, type="dotted" ) l.label = "slope" k = biggles.PlotKey( .1, .9, [a,b,l] ) p.add( l, a, b, k ) #p.write_img( 400, 400, "example2.png" ) #p.write_eps( "example2.eps" ) p.show() python2-biggles-1.6.6/examples/example5.py0000755000175100017510000000110310611710021017452 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import math, numpy x = numpy.arange( 0, 3*math.pi, math.pi/10 ) y = numpy.sin(x) a = biggles.FramedArray( 2, 2, title='title' ) a.aspect_ratio = 0.75 a.xlabel = "x label" a.ylabel = "y label" a.uniform_limits = 1 a.cellspacing = 1. a.add( biggles.LineY(0, type='dot') ) a[0,0].add( biggles.Curve(x, .25*y) ) a[0,1].add( biggles.Curve(x, .50*y) ) a[1,0].add( biggles.Curve(x, .75*y) ) a[1,1].add( biggles.Curve(x, y) ) #a.write_img( 400, 400, "example5.png" ) #a.write_eps( "example5.eps" ) a.show() python2-biggles-1.6.6/examples/example9.py0000755000175100017510000000235010611710021017463 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles from numpy import * def mag( vec ): return sqrt(sum(vec*vec, -1)) def make_coloredpoints_plot(): # This is the magic recipe for an array of points from (0,0) to (10,10) (x,y) = reshape(indices([10+1,10+1]), (2,-1)) # Let's color the points by their distance from the point (3,7) center = (3,7) rad = mag( transpose([x,y]) - center ) scaledrad = (1 - rad/max(rad))[:,newaxis] # Go from light blue to intense red. minColor = array([0.6, 0.9, 1.0]) maxColor = array([1.0, 0.2, 0.2]) colorrad = minColor + scaledrad*(maxColor-minColor) cp = biggles.ColoredPoints(x, y, colorrad, \ type='filled circle', size=6 ) # make plot p = biggles.FramedPlot() p.title = "Colored Points Plot" p.add( cp ) return p def make_density_plot(): a = reshape(arange(90.0), (5,6,3)) a[...,1] = 100 - a[...,1] d = biggles.Density( 1-(a/max(a.flat)), [[0,0], [5,10]] ) # make plot p = biggles.FramedPlot() p.title = "Density" p.add( d ) return p p1 = make_coloredpoints_plot() p2 = make_density_plot() t = biggles.Table( 1, 2 ) t.aspect_ratio = 0.5 t[0,0] = p1 t[0,1] = p2 #t.write_img( 400, 400, "example9.png" ) #t.write_eps( "example9.eps" ) t.show() python2-biggles-1.6.6/examples/example4.py0000755000175100017510000000116110611710021017455 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import math, numpy x = numpy.arange( 0, 2*math.pi, math.pi/20 ) s = numpy.sin(x) c = numpy.cos(x) inset = biggles.FramedPlot() inset.title = "inset" inset.frame.draw_ticks = 0 inset.add( biggles.Curve(x, s, type="dashed") ) p = biggles.FramedPlot() p.aspect_ratio = 1. p.frame.tickdir = +1 p.frame.draw_spine = 0 p.add( biggles.SymmetricErrorBarsY(x, s, [0.2]*len(x)) ) p.add( biggles.Points(x, s, color="red") ) p.add( biggles.Inset((.6,.6), (.95,.95), inset) ) #p.write_img( 400, 400, "example4.png" ) #p.write_eps( "example4.eps" ) p.show() python2-biggles-1.6.6/examples/example3.py0000755000175100017510000000101610611710021017453 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') import biggles import math, numpy x = numpy.arange( 0, 3*math.pi, math.pi/10 ) y = numpy.sin(x) p = biggles.FramedPlot() p.title = "Title" p.xlabel = "X axis" p.ylabel = "Y axis" p.add( biggles.Histogram(y) ) p.add( biggles.PlotLabel(.5, .5, "Histogram", color=0xcc0000) ) t1 = biggles.Table( 1, 2 ) t1[0,0] = p t1[0,1] = p t2 = biggles.Table( 2, 1 ) t2[0,0] = t1 t2[1,0] = p #t2.write_img( 400, 400, "example3.png" ) #t2.write_eps( "example3.eps" ) t2.show() python2-biggles-1.6.6/examples/example-matlab.py0000755000175100017510000000127110611710021020631 0ustar noltanolta#!/usr/bin/env python import sys sys.path.insert(1,'..') sys.ps1 = None import numpy from biggles.matlab import * def press_return(): print "[press return]" sys.stdin.readline() x = numpy.arange(-10,10); y = x**2; e = y/4 subplot(2,3,1) plot(list(x), list(y), 'ko-') subplot(2,3,2) plot(x, y, 'ro') subplot(2,3,3) plot(x, y, 'go') subplot(2,3,4) plot(x, y, 'b-') subplot(2,3,5) plot([0, 1], [0, 1], 'o') drawnow(width=500, height=200) press_return() drawnow() press_return() clf() plot(x, y, '.') drawnow() press_return() clf() plot(x, y, 'r*-') hold_on() plot(x, -y, 'bv-') errorbar(x, y/2, e, 'ko-') title('foo') xlabel('xbar') ylabel('ybar') hold_off() drawnow() press_return() python2-biggles-1.6.6/src/0000755000175100017510000000000011357716714014362 5ustar noltanoltapython2-biggles-1.6.6/src/config.pyc0000644000175100017510000000402611357716146016345 0ustar noltanolta v>c@s2ddkZddkZddkZeiatiddtiddtiddtid d!tid"d#tid$d%eiieiie dZ ti e ei i do-eiiei ddZti endZdZddZdZdZdS(&iNtscreentguess_interactivet persistenttHammerAitoffPlott num_b_ribstribs_bt num_l_ribstribs_lt readcolumnt use_numerict read_columnt return_numpyt comment_chartprintertpapert postscripts config.initHOMEs.bigglescCs ttdS(Ntps1(thasattrtsys(((s../src/config.pyt interactive3scCsDy2ti||d}|ddjodSnWn dSnXdS(Ntnoityi(t_configtget(tsectiontoptiontx((s../src/config.pytbool6s  cCsti|||S(N(RR(RRtnotfound((s../src/config.pytvalue?scCs ti|S(N(Rt get_section(R((s../src/config.pytoptionsCscGslt|djotid|d|dn7t|djo#ti|d|d|dndS(Nitdefaultiii(tlenRtset(targs((s../src/config.pyt configureGs(sscreenR(sscreens persistent(RR(RR(RR(RR(RR (R R (RR (R R (sprinterR(s postscriptR(tosRtconfittConfitRt deprecatedtpathtjointdirnamet__file__tSITECONFIGFILEtreadtenvironthas_keytUSERCONFIGFILERRtNoneRR R%(((s../src/config.pyss,      !    python2-biggles-1.6.6/src/__init__.py0000644000175100017510000000607011357715757016504 0ustar noltanolta# # $Id: __init__.py,v 1.82 2010/04/09 21:28:15 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # __version__ = '1.6.6' from biggles import \ Circle ,\ Circles ,\ ColoredPoint ,\ ColoredPoints ,\ Curve ,\ DataArc ,\ DataBox ,\ DataInset ,\ DataLabel ,\ DataLine ,\ Density ,\ Ellipse ,\ Ellipses ,\ ErrorBarsX ,\ ErrorBarsY ,\ FillAbove ,\ FillBelow ,\ FillBetween ,\ FramedArray ,\ FramedPlot ,\ Geodesic ,\ Histogram ,\ Labels ,\ LineX ,\ LineY ,\ LowerLimits ,\ OldCustomFramedPlot ,\ OldKey ,\ Plot ,\ PlotArc ,\ PlotBox ,\ PlotInset ,\ PlotKey ,\ PlotLabel ,\ PlotLine ,\ Point ,\ Points ,\ Slope ,\ SymmetricErrorBarsX ,\ SymmetricErrorBarsY ,\ Table ,\ Text ,\ UpperLimits ,\ multipage from config import \ configure from contour import \ Contour ,\ Contours from func import \ plot ,\ read_column ,\ read_matrix ,\ read_rows from hammer import \ HammerAitoffPlot # aliases Arc = DataArc Box = DataBox Inset = PlotInset Label = DataLabel Line = DataLine SymmetricXErrorBars = SymmetricErrorBarsX SymmetricYErrorBars = SymmetricErrorBarsY XErrorBars = ErrorBarsX YErrorBars = ErrorBarsY class _deprecated: def __init__( self, obj, old, new, harrass=1 ): self.obj = obj self.old = old self.new = new self.harrass = harrass def __call__( self, *args, **kw ): import sys if self.harrass == 1: sys.stderr.write( \ "biggles: %s is deprecated - use %s instead\n" \ % (self.old, self.new) ) return apply( self.obj, args, kw ) # XXX:deprecated 1.0 Plot2D = _deprecated( FramedPlot, "Plot2D", "FramedPlot" ) # XXX:deprecated 1.3 ErrorEllipses = _deprecated( Ellipses, "ErrorEllipses", "Ellipses" ) LabelData = _deprecated( DataLabel, "LabelData", "DataLabel" ) LabelPlot = _deprecated( PlotLabel, "LabelPlot", "PlotLabel" ) LineKey = _deprecated( OldKey, "LineKey", "PlotKey" ) LineSlope = _deprecated( Slope, "LineSlope", "Slope" ) SymbolKey = _deprecated( OldKey, "SymbolKey", "PlotKey" ) # XXX:deprecated 1.5 CustomFramedPlot = _deprecated( \ OldCustomFramedPlot, "CustomFramedPlot", "FramedPlot", 0 ) readcolumn = _deprecated( read_column, "readcolumn", "read_column", 0 ) try: del _biggles del biggles del config del contour del func del geometry del hammer except NameError: pass python2-biggles-1.6.6/src/matlab.py0000644000175100017510000001360010611710022016146 0ustar noltanolta# # $Id: matlab.py,v 1.5 2007/04/19 15:51:46 mrnolta Exp $ # # Copyright (C) 2001 : # # Jamie Mazer # Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # # matlab-like quick plot tools # # import biggles.matlab # # plot(x,y,style) # hist(n, nbins) # errorbar(x,y,e,style) # hold_on() # hold_off() # clf() # drawnow() **required** # subplot(nr,nc,n) or subplot(nr,nc,r,c) (note: r & c zerobased) # # NOTE: PLOTS ARE NOT DRAWN UNTIL YOU CALL DRAWNOW()!! # import biggles import math import numpy import string class _MatlabEmulation: LINES = [ "solid", "longdashed", "dotted" ] SYMBOLS = [ "filled circle", "plus", "asterisk", "circle", "cross", "square", "triangle", "diamond", "star", "inverted triangle", "octagon", "filled square", "filled triangle", "filled diamond", "filled inverted triangle" ] COLORS = [ "black", "red", "green", "blue", "magenta", "cyan" ] LAST = None HOLD = None TABLE = None NROWS = 1 NCOLS = 1 R = 0 C = 0 def parse_style( self, s ): l,c,d = None, 'black', None if string.find(s, '--') >= 0: l = 'longdashed' s = string.replace(s, '--', '') elif string.find(s, '-') >= 0: l = 'solid' s = string.replace(s, '-', '') elif string.find(s, ':') >= 0: l = 'dotted' s = string.replace(s, ':', '') if 'y' in s: c='yellow' elif 'm' in s: c='magenta' elif 'c' in s: c='cyan' elif 'r' in s: c='red' elif 'g' in s: c='green' elif 'b' in s: c='blue' elif 'k' in s: c='black' elif 'w' in s: c='white' if '.' in s: d = 'dot' elif 'o' in s: d = 'filled circle' elif 'x' in s: d = 'cross' elif '+' in s: d = 'plus' elif '*' in s: d = 'asterisk' elif 's' in s: d = 'filled square' elif 'd' in s: d = 'filled diamond' elif '^' in s: d = 'triangle' elif 'v' in s: d = 'inverted triangle' elif '<' in s: d = 'filled triangle' elif '>' in s: d = 'filled inverted triangle' elif 'p' in s: d = 'octagon' elif 'h' in s: d = 'filled octagon' return l,c,d def get_table( self ): if self.TABLE is None: self.TABLE = biggles.Table( self.NROWS, self.NCOLS ) return self.TABLE def get_plot( self, p=None ): if p is None: if self.HOLD: p = self.HOLD else: t = self.get_table() p = biggles.FramedPlot() t[ self.R, self.C ] = p try: nth = p.mplotnum + 1 except KeyError: nth = 0 p.mplotnum = nth return p def get_style( self, p, style=None ): n = p.mplotnum if style: return self.parse_style( style ) else: return self.LINES[n], self.COLORS[n], self.SYMBOLS[n] _matlab = _MatlabEmulation() def subplot( nr, nc, r, c=None ): global _matlab if _matlab.NROWS != nr or _matlab.NCOLS != nc: _matlab.TABLE = None _matlab.NROWS = nr _matlab.NCOLS = nc if c is None: _matlab.R = int(float(r-1)/float(nc)) _matlab.C = int(0.5+math.fmod(float(r)-1.0, float(nc))) else: _matlab.R = r _matlab.C = c def hold_on(): global _matlab _matlab.HOLD = _matlab.LAST def hold_off(): global _matlab _matlab.HOLD = None def clf(): global _matlab _matlab.LAST = None _matlab.HOLD = None _matlab.TABLE = None _matlab.NROWS = 1 _matlab.NCOLS = 1 _matlab.R = 0 _matlab.C = 0 def drawnow( width=None, height=None ): global _matlab if _matlab.TABLE: _matlab.TABLE.show( width=width, height=height ) def xlabel( s ): global _matlab if _matlab.LAST: _matlab.LAST.xlabel = s def ylabel( s ): global _matlab if _matlab.LAST: _matlab.LAST.ylabel = s def title( s ): global _matlab if _matlab.LAST: _matlab.LAST.title = s def plot( x=None, y=None, style=None, show=None, p=None ): global _matlab p = _matlab.get_plot( p ) lstyle, color, mstyle = _matlab.get_style( p, style ) if y is None: y = x x = range(len(y)) if mstyle is not None: p.add(biggles.Points(x, y, color=color, symboltype=mstyle)) if lstyle is not None: p.add(biggles.Curve(x, y, color=color, linetype=lstyle)) if show: p.show() _matlab.LAST = p return p def errorbar( x, y, e, style='ko-', show=None, p=None ): global _matlab p = _matlab.get_plot( p ) lstyle, color, mstyle = _matlab.get_style( p, style ) p.add( biggles.SymmetricErrorBarsY(x, y, e, color=color) ) if mstyle is not None: p.add( biggles.Points(x, y, color=color, type=mstyle) ) if lstyle is not None: p.add( biggles.Curve(x, y, color=color, type=lstyle) ) if show: p.show() _matlab.LAST = p return p def hist( v, nbins=10, vmin=None, vmax=None, show=None, p=None ): global _matlab p = _matlab.get_plot( p ) if vmin is None: vmin = float(min(v)) if vmax is None: vmax = float(max(v)) binwidth = (vmax - vmin) / float(nbins-1) x = numpy.arrayrange( vmin, vmax+binwidth, binwidth ) y = numpy.zeros( x.shape, int ) for i in range(len(v)): n = int(round((float(v[i]) - vmin) / binwidth, 0)) try: y[n] = y[n] + 1 except IndexError: pass xx = numpy.zeros( 2*len(x) + 3 ) yy = numpy.zeros( 2*len(y) + 3 ) xx[0] = x[0] yy[0] = 0 for i in range(0, len(x)): xx[1+2*i],xx[1+2*i+1] = x[i],x[i]+binwidth yy[1+2*i],yy[1+2*i+1] = y[i],y[i] xx[1+2*i+2] = x[i]+binwidth yy[1+2*i+2] = 0; xx[1+2*i+3] = x[0]; yy[1+2*i+3] = 0; p.add( biggles.FillBelow(xx, yy), biggles.Curve(xx, yy) ) p.yrange = 0, max(y) if show is not None: p.show() _matlab.LAST = p return p python2-biggles-1.6.6/src/Makefile0000644000175100017510000000171710611710022016002 0ustar noltanolta# # $Id: Makefile,v 1.11 2007/04/19 15:51:46 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # include ../make.inc CPPFLAGS = $(BASE_CPPFLAGS) $(NUMPY_CPPFLAGS) LDFLAGS = $(BASE_LDFLAGS) TARGETS = _biggles.so include ../make.rules python2-biggles-1.6.6/src/contour.py0000644000175100017510000001261510747523277016434 0ustar noltanolta# # $Id: contour.py,v 1.23 2008/01/29 04:08:31 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # from biggles import \ _series, _message, \ _LineComponent, _PathObject, _PlotComponent, BigglesError from geometry import * import _biggles import numpy def _span( a, b, n ): return a + float(b - a)*numpy.arange( 0, n, 1, numpy.Float )/(n-1) def _pop2( x, i, j ): if i < j: b = x.pop( j ) a = x.pop( i ) elif i > j: a = x.pop( i ) b = x.pop( j ) return a, b def _unzip( line ): x = [] y = [] for x0,y0 in line: x.append( x0 ) y.append( y0 ) return x, y class Contour( _LineComponent ): def __init__( self, x, y, z, z0, **kw ): _LineComponent.__init__( self ) self.kw_init( kw ) self.x = x self.y = y self.z = z self.z0 = z0 def limits( self ): p = min(self.x), min(self.y) q = max(self.x), max(self.y) return BoundingBox( p, q ) def _get_contours( self ): segs = _biggles.contour_segments( \ self.x, self.y, self.z, self.z0 ) open = [[ segs[0][0], segs[0][1] ]] closed = [] for a,b in segs[1:]: xxx = [] for i in range(len(open)): begin = open[i][0] end = open[i][-1] if a == begin: xxx.append( (i,0,b) ) elif a == end: xxx.append( (i,1,b) ) if b == begin: xxx.append( (i,0,a) ) elif b == end: xxx.append( (i,1,a) ) if len(xxx) == 0: open.append( [a,b] ) elif len(xxx) == 1: i,end,pt = xxx[0] if end == 0: open[i].insert( 0, pt ) else: open[i].append( pt ) elif len(xxx) == 2: i0,end0,pt0 = xxx[0] i1,end1,pt1 = xxx[1] if i0 == i1: # closed l0 = open.pop( i0 ) l0.append( l0[0] ) closed.append( l0 ) else: l0, l1 = _pop2( open, i0, i1 ) m = None if end0==1 and end1==0: m = l0 + l1 elif end0==0 and end1==1: m = l1 + l0 elif end0==0 and end1==0: l0.reverse() m = l0 + l1 elif end0==1 and end1==1: l1.reverse() m = l0 + l1 if m is not None: open.append( m ) else: _message( "contour: m is None" ) elif len(xxx) > 2: _message( "contour: len(xxx) > 2" ) return open + closed def make( self, context ): lines = self._get_contours() for line in lines: x, y = _unzip( line ) u, v = context.geom.call_vec( x, y ) self.add( _PathObject(u, v) ) def _func_color_black( i, n, z0, z_min, z_max ): return 0x000000 def _func_linetype_dotneg( i, n, z0, z_min, z_max ): if z0 < 0: return "dotted" return "solid" def _func_linewidth_placeholder( i, n, z0, z_min, z_max ): return 1 class Contours( _PlotComponent ): _named_func_color = { "black" : _func_color_black, } _named_func_linetype = { "dotted-negative" : _func_linetype_dotneg, } _named_func_linewidth = { "placeholder" : _func_linewidth_placeholder, } def __init__( self, z, x=None, y=None, zrange=None, **kw ): _PlotComponent.__init__( self ) #apply( self.conf_setattr, ("Contours",), kw ) self.conf_setattr( "Contours" ) self.kw_init( kw ) self.z = z self.x = x self.y = y self.zrange = zrange def _get_coords( self ): dim = self.z.shape x = self.x if x is None: x = range(dim[0]) y = self.y if y is None: y = range(dim[1]) return x, y, self.z def limits( self ): x, y, z = self._get_coords() return BoundingBox( (min(x),min(y)), (max(x),max(y)) ) def make( self, context ): self.clear() x, y, z = self._get_coords() limits = self.limits() xr = limits.xrange() yr = limits.yrange() zr = self.zrange if zr is None: zr = _biggles.range( z ) levels = self.levels if type(levels) == type(0): levels = _series( 1, self.levels, \ float(zr[1]-zr[0])/(self.levels+1), zr[0] ) colorfunc = self.func_color if type(colorfunc) == type(""): colorfunc = self._named_func_color[colorfunc] linefunc = self.func_linetype if type(linefunc) == type(""): linefunc = self._named_func_linetype[linefunc] widthfunc = self.func_linewidth if type(widthfunc) == type(""): widthfunc = self._named_func_linewidth[widthfunc] nlevels = len(levels) for i in range(nlevels): kw = {} z0 = levels[i] args = i, nlevels, z0, zr[0], zr[1] if colorfunc is not None: color = apply( colorfunc, args ) if color is not None: kw["color"] = color if linefunc is not None: linetype = apply( linefunc, args ) if linetype is not None: kw["linetype"] = linetype if widthfunc is not None: linewidth = apply( widthfunc, args ) if linewidth is not None: kw["linewidth"] = linewidth c = apply( Contour, (x, y, z, z0), kw ) self.add( c ) def make_key( self, bbox ): xr = bbox.xrange() y = bbox.center()[1] p = xr[0], y q = xr[1], y return apply( _LineObject, (p,q), self.kw_style ) python2-biggles-1.6.6/src/confit.py0000644000175100017510000000511207271720037016206 0ustar noltanolta# # $Id: confit.py,v 1.2 2001/04/26 04:12:15 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import ConfigParser from string import atoi, split, strip def _atox( x ): x = strip( x ) if x == "None": return None try: return atoi( x, 0 ) except ValueError: try: return float(x) except ValueError: pass if x[0] == "{" and x[-1] == "}": style = {} pairs = map( strip, split(x[1:-1], ",") ) for pair in pairs: if pair == "": continue key,val = split( pair, ":" ) style[ strip(key) ] = _atox( strip(val) ) return style return x class Confit: default_sect = "default" def __init__( self ): self._sections = {} self._deprecated = {} def _defaults( self ): return self._sections[ self.default_sect ] def _get( self, section, option ): return self._sections[section][option] def _set( self, section, option, value ): if not self._sections.has_key( section ): self._sections[section] = {} self._sections[section][option] = value def deprecated( self, old, new ): self._deprecated[old] = new def get( self, section, option, notfound=None ): try: rval = self._get( section, option ) except KeyError: try: rval = self._defaults()[option] except KeyError: rval = notfound return rval def get_section( self, section ): if not self._sections.has_key( section ): return None return self._sections[section] def set( self, section, option, value ): if self._deprecated.has_key( (section,option) ): sect,opt = self._deprecated[ (section,option) ] self._set( sect, opt, value ) else: self._set( section, option, value ) def read( self, filename ): cp = ConfigParser.ConfigParser() cp.read( filename ) for section in cp.sections(): for option in cp.options( section ): if option == "__name__": continue a = cp.get( section, option, raw=1 ) self.set( section, option, _atox(a) ) python2-biggles-1.6.6/src/geometry.py0000755000175100017510000001335310611710022016551 0ustar noltanolta# # $Id: geometry.py,v 1.25 2007/04/19 15:51:46 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import math, numpy # pt_* functions -------------------------------------------------------------- def pt_add( u, v ): return u[0] + v[0], u[1] + v[1] def pt_sub( u, v ): return u[0] - v[0], u[1] - v[1] def pt_mul( a, u ): return a * u[0], a * u[1] def pt_rot( u, angle ): c, s = math.cos(angle), math.sin(angle) return c*u[0] - s*u[1], s*u[0] + c*u[1] def pt_len( u ): return math.hypot( u[0], u[1] ) def pt_angle( u ): return math.atan2( u[1], u[0] ) def pt_unit( u ): r = pt_len(u) return u[0]/r, u[1]/r def pt_min( a, b ): if a is None: return b if b is None: return a return min(a[0],b[0]), min(a[1],b[1]) def pt_max( a, b ): if a is None: return b if b is None: return a x = max( a[0], b[0] ) if x is None: x = min( a[0], b[0] ) y = max( a[1], b[1] ) if y is None: y = min( a[1], b[1] ) return x, y # BoundingBox ----------------------------------------------------------------- class BoundingBox: def __init__( self, *args ): if len(args) > 0: self.p0 = reduce( pt_min, args ) self.p1 = reduce( pt_max, args ) else: self.p0 = None self.p1 = None def __str__( self ): return "(%s,%s)" % (str(self.p0), str(self.p1)) def copy( self ): return BoundingBox( self.p0, self.p1 ) def is_null( self ): return self.p0 is None or self.p1 is None def width( self ): if self.is_null(): return None else: return abs( self.p0[0] - self.p1[0] ) def height( self ): if self.is_null(): return None else: return abs( self.p0[1] - self.p1[1] ) def diagonal( self ): if self.is_null(): return None else: return math.hypot( self.width(), self.height() ) def aspect_ratio( self ): if self.is_null(): return None else: return self.height()/self.width() def xrange( self ): if self.is_null(): return None else: return self.p0[0], self.p1[0] def yrange( self ): if self.is_null(): return None else: return self.p0[1], self.p1[1] def lowerleft( self ): if self.is_null(): return None else: return self.p0 def upperleft( self ): if self.is_null(): return None else: return self.p0[0], self.p1[1] def upperright( self ): if self.is_null(): return None else: return self.p1 def lowerright( self ): if self.is_null(): return None else: return self.p1[0], self.p0[1] def center( self ): x = self.xrange() y = self.yrange() return (x[0]+x[1])/2., (y[0]+y[1])/2. def union( self, other ): self.p0 = pt_min( self.p0, other.p0 ) self.p1 = pt_max( self.p1, other.p1 ) def deform( self, dt, db, dl, dr ): self.p0 = pt_sub( self.p0, (dl,db) ) self.p1 = pt_add( self.p1, (dr,dt) ) def shift( self, dp ): self.p0 = pt_add( self.p0, dp ) self.p1 = pt_add( self.p1, dp ) def expand( self, factor ): dp = pt_mul( factor/2., (self.width(), self.height()) ) self.p0 = pt_sub( self.p0, dp ) self.p1 = pt_add( self.p1, dp ) def rotate( self, angle, p ): a = pt_add(pt_rot(pt_sub( self.lowerleft(), p), angle), p) b = pt_add(pt_rot(pt_sub(self.lowerright(), p), angle), p) c = pt_add(pt_rot(pt_sub( self.upperleft(), p), angle), p) d = pt_add(pt_rot(pt_sub(self.upperright(), p), angle), p) self.p0 = pt_min( a, pt_min( b, pt_min( c, d ) ) ) self.p1 = pt_max( a, pt_max( b, pt_max( c, d ) ) ) def make_aspect_ratio( self, ratio ): if ratio < self.aspect_ratio(): dh = self.height() - ratio * self.width() self.p0 = self.p0[0], self.p0[1] + dh/2 self.p1 = self.p1[0], self.p1[1] - dh/2 else: dw = self.width() - self.height() / ratio self.p0 = self.p0[0] + dw/2, self.p0[1] self.p1 = self.p1[0] - dw/2, self.p1[1] def contains( self, q ): if self.p0[0] <= q[0] and \ q[0] <= self.p1[0] and \ self.p0[1] <= q[1] and \ q[1] <= self.p1[1]: return 1 else: return 0 # AffineTransform ------------------------------------------------------------- def _matrix_multipy( A, B ): C00 = A[0][0] * B[0][0] + A[0][1] * B[1][0] C01 = A[0][0] * B[0][1] + A[0][1] * B[1][1] C10 = A[1][0] * B[0][0] + A[1][1] * B[1][0] C11 = A[1][0] * B[0][1] + A[1][1] * B[1][1] return (C00, C01), (C10, C11) class AffineTransform: def __init__( self ): self.t = 0., 0. self.m = (1., 0.), (0., 1.) def __call__( self, x, y ): p = self.t[0] + self.m[0][0] * x + self.m[0][1] * y q = self.t[1] + self.m[1][0] * x + self.m[1][1] * y return p, q def call_vec( self, x, y ): x_ = numpy.asarray( x ) y_ = numpy.asarray( y ) p = self.t[0] + self.m[0][0] * x_ + self.m[0][1] * y_ q = self.t[1] + self.m[1][0] * x_ + self.m[1][1] * y_ return p, q def compose( self, other ): self.t = self( other.t[0], other.t[1] ) self.m = _matrix_multiply( self.m, other.m ) class RectilinearMap( AffineTransform ): def __init__( self, src, dest ): AffineTransform.__init__( self ) sx = dest.width() / src.width() sy = dest.height() / src.height() p, q = dest.lowerleft(), src.lowerleft() tx = p[0] - sx * q[0] ty = p[1] - sy * q[1] self.t = tx, ty self.m = ( sx, 0. ), ( 0., sy ) python2-biggles-1.6.6/src/hammer.py0000644000175100017510000000771307367205325016212 0ustar noltanolta# # $Id: hammer.py,v 1.25 2001/10/29 07:52:53 mrnolta Exp $ # # Copyright (C) 2000-2001 : # # Walter Brisken # Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # # Hammer-Aitoff coordinates are an equal area projection of the # sphere into the plane. The spherical coordinates l and b are # used where l runs from -pi to pi and b from -pi/2 to pi/2. # The equator is b=0, and b = +/-pi/2 are the north/south poles. # import math from biggles import \ _series, _PlotComposite, _PlotGeometry, _PlotContainer, Geodesic, Curve from geometry import * import _biggles class _HammerAitoffGeometry: def __init__( self, dest, l0=0., b0=0, rot=0. ): self.src_bbox = BoundingBox( (-1.,-.5), (1.,.5) ) self.dest_bbox = dest self.aff = RectilinearMap( self.src_bbox, dest ) self.l0 = l0 self.b0 = b0 self.rot = rot def __call__( self, l_, b_ ): xh, yh = _biggles.hammer_call( \ l_, b_, self.l0, self.b0, self.rot ) return self.aff( xh, yh ) def call_vec( self, l_, b_ ): xh, yh = _biggles.hammer_call_vec( \ l_, b_, self.l0, self.b0, self.rot ) return self.aff.call_vec( xh, yh ) def geodesic( self, l_, b_, div=2 ): l, b = _biggles.hammer_geodesic_fill( l_, b_, div ) segs = [] i0 = 0 for i in range(1,len(l)): if _biggles.hammer_connect( \ l[i-1], b[i-1], l[i], b[i], \ self.l0, self.b0, self.rot ): segs.append( (l[i0:i],b[i0:i]) ) i0 = i segs.append( (l[i0:],b[i0:]) ) return segs class _HammerAitoffContext: def __init__( self, device, dev, l0=0., b0=0., rot=0. ): self.draw = device self.dev_bbox = dev self.geom = _HammerAitoffGeometry( dev, l0, b0, rot ) self.plot_geom = _PlotGeometry( BoundingBox((0,0),(1,1)), dev ) def do_clip( self ): pass class HammerAitoffPlot( _PlotContainer ): _attr_deprecated = { "num_l_ribs" : "ribs_l", "num_b_ribs" : "ribs_b", } def __init__( self, l0=0., b0=0, rot=0., **kw ): apply( _PlotContainer.__init__, (self,) ) apply( self.conf_setattr, ("HammerAitoffPlot",), kw ) self.content = _PlotComposite() self.l0 = l0 self.b0 = b0 self.rot = rot _attr_deprecated = { "num_l_ribs" : "ribs_l", "num_b_ribs" : "ribs_b", } def __setattr__( self, name, value ): self.__dict__[ self._attr_deprecated.get(name,name) ] = value def __iadd__( self, other ): self.add( other ) def add( self, *args ): apply( self.content.add, args ) def _draw_background( self, context ): pc = _PlotComposite() nl = self.ribs_l b = _series( -90/2, 90/2, 2*math.pi/180. ) for l0 in _series( -nl, nl, math.pi/nl ): c = apply( Curve, ([l0]*len(b), b), self.ribs_style ) pc.add( c ) nb = self.ribs_b l = _series( -180/2, 180/2, 2*math.pi/180. ) for b0 in _series( -nb, nb, 0.5*math.pi/(nb+1) ): c = apply( Curve, (l, [b0]*len(l)), self.ribs_style ) pc.add( c ) pc.render( context ) def exterior( self, device, interior ): bb = interior.copy() context = _HammerAitoffContext( device, interior, self.l0, self.b0, self.rot ) bb.union( self.content.bbox(context) ) return bb def compose_interior( self, device, interior ): _PlotContainer.compose_interior( self, device, interior ) context = _HammerAitoffContext( device, interior, self.l0, self.b0, self.rot ) self._draw_background( context ) self.content.render( context ) python2-biggles-1.6.6/src/_biggles.c0000644000175100017510000002567010611710022016265 0ustar noltanolta/* * $Id: _biggles.c,v 1.19 2007/04/19 15:51:46 mrnolta Exp $ * * Copyright (C) 2001 Mike Nolta * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #include #include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #define PyArray_1D(v,i)\ (*((double *)((v)->data+(i)*(v)->strides[0]))) #define PyArray_1D_ptr(v,i)\ ((double *)((v)->data+(i)*(v)->strides[0])) #define PyArray_2D(m,i,j)\ (*((double *)((m)->data+(i)*(m)->strides[0]+(j)*(m)->strides[1]))) /* * I wish min/max(z) worked. */ #define BGL_MIN(a,b) (((a) < (b)) ? (a) : (b)) #define BGL_MAX(a,b) (((a) > (b)) ? (a) : (b)) static PyObject * biggles_range( PyObject *self, PyObject *args ) { PyObject *input; PyArrayObject *x; int i, n; double *dp, min, max; if ( !PyArg_ParseTuple(args, "O", &input) ) return NULL; x = (PyArrayObject *) PyArray_ContiguousFromObject( input, PyArray_DOUBLE, 0, 0 ); if ( x == NULL ) return NULL; n = PyArray_Size( input ); dp = (double *) x->data; min = max = dp[0]; for ( i = 1; i < n; i++ ) { min = BGL_MIN( min, dp[i] ); max = BGL_MAX( max, dp[i] ); } Py_DECREF(x); return Py_BuildValue( "dd", min, max ); } /****************************************************************************** * contour.py * * The problem is, given a 2D matrix, draw isocontours. This is * basically an exercise in interpolation, considering the matrix * to be the values of a function sampled on a regular grid. * * So it boils down to how best to interpolate a 2D function over * a rectangular area given only the values at the corners. * * The simplest solution would be a plane, but 4 points aren't * necessarily coplanar. And the next simplest smooth function, * a quadratic, is underdetermined. The "solution" seems to be * to add a fifth point, the average of the four corner points. * * * z[i,j+1] = p1 o-----------o p2 = z[i+1,j+1] * | + + | * | + + | * | o <---+--- p4 = average(p0,p1,p2,p3) * | + + | * | + + | * z[i,j] = p0 o-----------o p3 = z[i+1,j] * * * This breaks the square up into four simplicies (triangles), * each of which defines a plane. The algorithm is then simply * figure out whether the simplex intersects the desired plane * and ifso add a line segment to the render list. * * Downside is that the output is a bunch of tiny unconnected line * segments, which bloats postscript files and slows down rendering. * Have to connect the dots at some point. * */ #define MAX_SEGS 4 static int _find_zero( double p[3], double q[3], double zero[2] ) { double a; if ( p[2] == 0. ) { zero[0] = p[0]; zero[1] = p[1]; return 1; } else if ( p[2]*q[2] < 0. ) { a = p[2]/(p[2] - q[2]); zero[0] = p[0] + a*(q[0] - p[0]); zero[1] = p[1] + a*(q[1] - p[1]); return 1; } return 0; } static int _pixel_interpolate( PyArrayObject *x, PyArrayObject *y, PyArrayObject *z, double z0, int i, int j, double segs[MAX_SEGS][4] ) { int k, l, ii, jj, kk; double p[5][3], zeros[3][2]; int nz, ns; for ( l = 0; l < 3; l++ ) p[4][l] = 0.; for ( k = 0; k < 4; k++ ) { ii = i + (k/2 % 2); jj = j + ((k+1)/2 % 2); p[k][0] = PyArray_1D(x,ii); p[k][1] = PyArray_1D(y,jj); p[k][2] = PyArray_2D(z,ii,jj) - z0; for ( l = 0; l < 3; l++ ) p[4][l] += 0.25 * p[k][l]; } ns = 0; for ( k = 0; k < 4; k++ ) { kk = (k + 1) % 4; nz = 0; nz += _find_zero( p[4], p[k], zeros[nz] ); nz += _find_zero( p[k], p[kk], zeros[nz] ); nz += _find_zero( p[kk], p[4], zeros[nz] ); if ( nz == 2 ) { segs[ns][0] = zeros[0][0]; segs[ns][1] = zeros[0][1]; segs[ns][2] = zeros[1][0]; segs[ns][3] = zeros[1][1]; ns++; } } return ns; } static PyObject * biggles_contour_segments( PyObject *self, PyObject *args ) { PyObject *ox, *oy, *oz, *list, *ref; PyArrayObject *x, *y, *z; double z0; double segs[MAX_SEGS][4]; int i, j, k, ns; list = NULL; if ( !PyArg_ParseTuple(args, "OOOd", &ox, &oy, &oz, &z0) ) return NULL; x = (PyArrayObject *) PyArray_ContiguousFromObject( ox, PyArray_DOUBLE, 1, 1 ); y = (PyArrayObject *) PyArray_ContiguousFromObject( oy, PyArray_DOUBLE, 1, 1 ); z = (PyArrayObject *) PyArray_ContiguousFromObject( oz, PyArray_DOUBLE, 2, 2 ); if ( x == NULL || y == NULL || z == NULL ) goto quit; if ( z->dimensions[0] != x->dimensions[0] || z->dimensions[1] != y->dimensions[0] ) { PyErr_SetString( PyExc_ValueError, "array dimensions are not compatible" ); goto quit; } list = PyList_New( 0 ); if ( list == NULL ) goto quit; for ( i = 0; i < z->dimensions[0]-1; i++ ) for ( j = 0; j < z->dimensions[1]-1; j++ ) { ns = _pixel_interpolate( x, y, z, z0, i, j, segs ); for ( k = 0; k < ns; k++ ) { ref = Py_BuildValue( "((dd)(dd))", segs[k][0], segs[k][1], segs[k][2], segs[k][3] ); PyList_Append( list, ref ); Py_DECREF(ref); /* ??? */ } } quit: Py_XDECREF(x); Py_XDECREF(y); Py_XDECREF(z); return list; } /****************************************************************************** * hammer.py */ static void _lb2xyz( double l, double b, double *x, double *y, double *z ) { *x = cos(b)*cos(l); *y = cos(b)*sin(l); *z = sin(b); } static void _xyz2lb( double x, double y, double z, double *l, double *b) { *l = atan2( y, x ); *b = asin( z/sqrt(x*x + y*y + z*z) ); } static void _x_rotate( double l, double b, double theta, double *ll, double *bb ) { double x, y, z, y2, z2; _lb2xyz( l, b, &x, &y, &z ); y2 = cos(theta)*y - sin(theta)*z; z2 = cos(theta)*z + sin(theta)*y; _xyz2lb( x, y2, z2, ll, bb ); } static void _y_rotate( double l, double b, double theta, double *ll, double *bb ) { double x, y, z, x2, z2; _lb2xyz( l, b, &x, &y, &z ); x2 = cos(theta)*x - sin(theta)*z; z2 = cos(theta)*z + sin(theta)*x; _xyz2lb( x2, y, z2, ll, bb ); } static void _z_rotate( double l, double b, double theta, double *ll, double *bb ) { *ll = atan2( sin(l+theta), cos(l+theta) ); *bb = b; } static void _lb_input( double l, double b, double l0, double b0, double rot, double *ll, double *bb ) { double p, q, r, s; _z_rotate( l, b, -l0, &p, &q ); _y_rotate( p, q, -b0, &r, &s ); _x_rotate( r, s, rot, ll, bb ); } static void _lb2uv( double l, double b, double *u, double *v ) { double q; q = sqrt( 1. + cos(b)*cos(0.5*l) ); *u = cos(b)*sin(0.5*l)/q; *v = 0.5*sin(b)/q; } static PyObject * biggles_hammer_call( PyObject *self, PyObject *args ) { double l, b, l0, b0, rot; double ll, bb, u, v; if ( !PyArg_ParseTuple(args, "ddddd", &l, &b, &l0, &b0, &rot) ) return NULL; _lb_input( l, b, l0, b0, rot, &ll, &bb ); _lb2uv( ll, bb, &u, &v ); return Py_BuildValue( "dd", u, v ); } static PyObject * biggles_hammer_call_vec( PyObject *self, PyObject *args ) { PyObject *ol, *ob, *ret; PyArrayObject *l, *b, *u, *v; double l0, b0, rot; double ll, bb; int i, n; ret = NULL; if ( !PyArg_ParseTuple(args, "OOddd", &ol, &ob, &l0, &b0, &rot) ) return NULL; l = (PyArrayObject *) PyArray_ContiguousFromObject( ol, PyArray_DOUBLE, 1, 1 ); b = (PyArrayObject *) PyArray_ContiguousFromObject( ob, PyArray_DOUBLE, 1, 1 ); if ( l == NULL || b == NULL ) goto quit0; n = BGL_MIN( l->dimensions[0], b->dimensions[0] ); u = (PyArrayObject *) PyArray_FromDims( 1, &n, PyArray_DOUBLE ); v = (PyArrayObject *) PyArray_FromDims( 1, &n, PyArray_DOUBLE ); if ( u == NULL || v == NULL ) goto quit1; for ( i = 0; i < n; i++ ) { _lb_input( PyArray_1D(l,i), PyArray_1D(b,i), l0, b0, rot, &ll, &bb ); _lb2uv( ll, bb, PyArray_1D_ptr(u,i), PyArray_1D_ptr(v,i) ); } ret = Py_BuildValue( "OO", u, v ); quit1: Py_XDECREF(u); Py_XDECREF(v); quit0: Py_XDECREF(l); Py_XDECREF(b); return ret; } static void _lb_geodesic( int div, double l0, double b0, double l1, double b1, double l[], double b[] ) { double lr0, br0, lr1, br1; double db; int i; _z_rotate( l1, b1, -l0, &lr0, &br0 ); _y_rotate( lr0, br0, -b0+M_PI/2, &lr1, &br1 ); l[0] = l0; b[0] = b0; db = (br1 - M_PI/2)/div; for ( i = 1; i < div; i++ ) { _y_rotate( lr1, M_PI/2 + i*db, -M_PI/2+b0, &lr0, &br0 ); _z_rotate( lr0, br0, l0, l+i, b+i ); } l[div] = l1; b[div] = b1; } static PyObject * biggles_hammer_geodesic_fill( PyObject *self, PyObject *args ) { PyObject *ol, *ob, *ref; PyArrayObject *l, *b, *l2, *b2; int i, n, div, dims[1]; ref = NULL; if ( !PyArg_ParseTuple(args, "OOi", &ol, &ob, &div) ) return NULL; l = (PyArrayObject *) PyArray_ContiguousFromObject( ol, PyArray_DOUBLE, 1, 1 ); b = (PyArrayObject *) PyArray_ContiguousFromObject( ob, PyArray_DOUBLE, 1, 1 ); if ( l == NULL || b == NULL ) { Py_XDECREF(l); Py_XDECREF(b); return NULL; } n = l->dimensions[0]; dims[0] = (n-1)*div + 1; l2 = (PyArrayObject *) PyArray_FromDims( 1, dims, PyArray_DOUBLE ); b2 = (PyArrayObject *) PyArray_FromDims( 1, dims, PyArray_DOUBLE ); if ( l2 == NULL || b2 == NULL ) goto quit; for ( i = 0; i < n-1; i++ ) _lb_geodesic( div, PyArray_1D(l,i), PyArray_1D(b,i), PyArray_1D(l,i+1), PyArray_1D(b,i+1), ((double *)l2->data) + i*div, ((double *)b2->data) + i*div ); ref = Py_BuildValue( "OO", l2, b2 ); quit: Py_DECREF(l); Py_DECREF(b); Py_XDECREF(l2); Py_XDECREF(b2); return ref; } static PyObject * biggles_hammer_connect( PyObject *self, PyObject *args ) { double l1, b1, l2, b2; double l0, b0, rot; double ll1, bb1, ll2, bb2; int connect; if ( !PyArg_ParseTuple(args, "ddddddd", &l1, &b1, &l2, &b2, &l0, &b0, &rot) ) return NULL; _lb_input( l1, b1, l0, b0, rot, &ll1, &bb1 ); _lb_input( l2, b2, l0, b0, rot, &ll2, &bb2 ); connect = sin(ll1)*sin(ll2) < 0.; return Py_BuildValue( "i", connect ); } /****************************************************************************** * module init */ static PyMethodDef BigglesMethods[] = { /* general */ { "range", biggles_range, METH_VARARGS }, /* contour.py */ { "contour_segments", biggles_contour_segments, METH_VARARGS }, /* hammer.py */ { "hammer_call", biggles_hammer_call, METH_VARARGS }, { "hammer_call_vec", biggles_hammer_call_vec, METH_VARARGS }, { "hammer_connect", biggles_hammer_connect, METH_VARARGS }, { "hammer_geodesic_fill", biggles_hammer_geodesic_fill, METH_VARARGS }, { NULL, NULL } }; void init_biggles( void ) { Py_InitModule( "_biggles", BigglesMethods ); import_array(); } python2-biggles-1.6.6/src/biggles.pyc0000644000175100017510000027220711357716146016524 0ustar noltanolta |=/Ic @sPddkZddkZddkZddkZddkZddkZddkZddkTddkZ e i Z d\Z Z dZ dZdZdZddd Zd Zd dd YZd efdYZdZdZdddYZdddYZdZdZdZdddYZdddYZdefdYZdefdYZ d efd!YZ!d"efd#YZ"d$e!fd%YZ#d&efd'YZ$d(efd)YZ%d*efd+YZ&d,efd-YZ'd.efd/YZ(d0efd1YZ)d2efd3YZ*d4efd5YZ+d6efd7YZ,d8efd9YZ-d:eefd;YZ.d<e.fd=YZ/d>e/fd?YZ0d@e/fdAYZ1dBe.fdCYZ2dDe2fdEYZ3dFe.fdGYZ4dHe4fdIYZ5dJe4fdKYZ6dLe4fdMYZ7dNe4fdOYZ8dPe4fdQYZ9dRe4fdSYZ:dTe4fdUYZ;dVe4fdWYZ<dXe4fdYYZ=dZe4fd[YZ>d\e4fd]YZ?d^e4fd_YZ@d`e.fdaYZAdbeAfdcYZBddZCdeeAfdfYZDdgZEdhe.fdiYZFdje.fdkYZGdleGfdmYZHdneGfdoYZIdpeGfdqYZJdre.fdsYZKdteKfduYZLdveKfdwYZMdxZNdyZOdze.fd{YZPd|ePfd}YZQd~ePfdYZRde.fdYZSddZUdZVdZWde.fdYZXddZYdZZddZ[ddZ\dZ]dZ^dZ_dZ`dZadZbddZcddZddddYZede.fdYZfdeffdYZgdeffdYZhde.fdYZidefdYZjdejfdYZkdZldZmdZndZodefdYZpdZqdZrdZsdepfdYZtdepfdYZudeufdYZvdddYZwdepfdYZxddZyddZzdZ{depfdYZ|depfdYZ}dddYZ~de~fdYZde~fdYZdS(iN(t*iicCstti|S(N(tlongtmathtfloor(tx((s../src/biggles.pyt_floor#scCstti|S(N(RRtceil(R((s../src/biggles.pyt_ceil&scCst|}|i|S(N(tlisttreverse(Rtl((s../src/biggles.pyt_tsil)s  cCs dG|GHdS(Nsbiggles:((ts((s../src/biggles.pyt_message.scCs#t||dt||dS(NcSs |||S(((Rtytz((s../src/biggles.pyt2si(tmaptrange(tmtntatb((s../src/biggles.pyt_series1scGs*x#|D]}|dj o|SqqWdS(N(tNone(targstarg((s../src/biggles.pyt_first_not_none4s   t_AliascBs5eZdZdZdZdZdZRS(cGs||idtdevtdataRERF((s../src/biggles.pyR s     cCsQ|ii}|ii}|iid|d|d|d|dfdS(Ntcliprectii(R]txrangetyrangeR\tset(Rtxrtyr((s../src/biggles.pytdo_clips(R.R/R Ri(((s../src/biggles.pyR[s cCs/t||i|i}|ii||dS(N(RAR]R\Rf(tcontextR,R*t device_size((s../src/biggles.pyt_kw_func_relative_fontsizescCs)t||i}|ii||dS(N(R9R]R\Rf(RjR,R*Rk((s../src/biggles.pyt_kw_func_relative_sizescCs-t|d|i}|ii||dS(Ng$@(R9R]R\Rf(RjR,R*t device_width((s../src/biggles.pyt_kw_func_relative_widthst_StyleKeywordscBsweZd ZhZhZhed<ed<edtt|iD]'}|ii|i||i|qWdS(N(RRRR\RR(RRjR((s../src/biggles.pyR\ss(ii(gg?(ii(ii(gg?(ii( R.R/RvRzR RRR5R\(((s../src/biggles.pyR@s         !! t_LineTextObjectcBs)eZhdd<ddeZheidddR"((s../src/biggles.pyR vs      cCsmtt|it|it|if}tt|it|it|if}t||S(N(RR=R>RR=RJ(RRR((s../src/biggles.pyR~s00c Cst|i|i}xtt|iD]}|i|i||i|}|i|i||i|}t ||}t |d|d|f|d|d|f}t |d|d|f|d|d|f}|i |||q+WdS(Nii( R9tbarsizeR]RRRR_R=R>RR( RRjR RRRtl0tl1tl2((s../src/biggles.pyRs  33(R.R/R RR(((s../src/biggles.pyR<ts  t ErrorBarsYcBs#eZdZdZdZRS(cKsFti||id|i|||_||_||_dS(NRC(R;R RRyRR=R>(RRR=R>R"((s../src/biggles.pyR s      cCsmt|itt|it|if}t|itt|it|if}t||S(N(RRR=R>R=RJ(RRR((s../src/biggles.pyRs00c Cst|i|i}xtt|iD]}|i|i||i|}|i|i||i|}t ||}t |d||df|d||df}t |d||df|d||df}|i |||q+WdS(Nii( R9R?R]RRRR_R=R>RR( RRjR RRRR@RARB((s../src/biggles.pyRs  33(R.R/R RR(((s../src/biggles.pyRCs  cKsOddk}t|i||}t|i||}tt|||f|S(Ni(toperatorRtsubRR!R<(RRterrR"RDtxlotxhi((s../src/biggles.pytSymmetricErrorBarsXs cKsOddk}t|i||}t|i||}tt|||f|S(Ni(RDRRERR!RC(RRRFR"RDtylotyhi((s../src/biggles.pytSymmetricErrorBarsYs t _ErrorLimitcBs2eZhdd<dd<dds0 !  (R.R/RzR R(((s../src/biggles.pyR],s      RcKs#||d= 1., b integral].igi g?i(gi(RtmodfRZtabstpowtint(RRR((s../src/biggles.pyt_magformas $   gcCs|djodSnt|\}}t|djoD|djo d|Sq~|djo d|Sq~d||fSn|d jo*t|\}}d t||fSnd |S( Nit0ig?s $10^{%d}$gs -$10^{%d}$s$%g\times 10^{%d}$gư>s%.*fs%g(RoRl(RRRR((s../src/biggles.pyt_format_ticklabelms      c Csg}tt||t|}tt||t|}|||}x1t||dD]}|i|||qiW|S(Ni(RRRRR%( R=R>tseptoriginRRRtr0R((s../src/biggles.pyt_ticklist_linear}s  cCstid|S(Ni (RRm(R((s../src/biggles.pyt_pow10scCs ti|S(N(RRZ(R((s../src/biggles.pyt_log10scCst|d|dd\}}|ddjo d}n=|d djo d}n"|d djo d}nd}|tid|}t|d|d|S( Niig@ig@ii iii(RoRRmRu(tlimRRRt major_div((s../src/biggles.pyt_ticks_default_linears"   cCst|dt|df}tti|d}tti|d}||d}|djottt|Sn6|djottt||dSn t|SdS(Niii i( RwRRRZRRRvRzR(Rxtlog_limtnlotnhitnn((s../src/biggles.pyt_ticks_default_logs   cCs`g}|d}|d|dt|d}x)t|D]}|i|||q=W|S(Nii(RRR%(RxtnumtticksRRR((s../src/biggles.pyt_ticks_num_linears   cCswg}ti|d}ti|d|t|d}x)t|D]}|i|||qKWtt|S(Nii(RRZRRR%RRv(RxRRRRR((s../src/biggles.pyt_ticks_num_logs% cCs|d|dtt|d}|djoHd}t|\}}d|jod djno d }qn|}|t|d}t|d|d||dS( Niiiig?iig@ii(RRRRoRu(RxRRRyt_numRRt minor_div((s../src/biggles.pyt_subticks_linears& "c CsAt|dt|df}tti|d}tti|d}||d}|djo&ttt|tt||Sn|djog}x|t|d|dD]c}xZtddD]I} | t|} |d| jo"| |djo|i | qqWqW|Snt|||SdS(Niii i( RwRRRZRRRvRRR%( RxRRR{R|R}R~t minor_ticksRtjR((s../src/biggles.pyt _subticks_logs"  & "t_GroupcBseZdZdZRS(cCs||_dS(N(R(RR((s../src/biggles.pyR scCs7t}x'|iD]}|i|i|qW|S(N(RJRRR5(RRjRR#((s../src/biggles.pyR5s   (R.R/R R5(((s../src/biggles.pyRs t _HalfAxiscBseZeefZeefZee fZ ee fZ hdd<dd<dd<ddt t|D]*}|i |i |||||qW|i \}} h|d<| d<} | i |itt||f| } |i| dS(NiRR(RRtticklabels_dirR9tticklabels_offsetR]t draw_ticksttickdirt ticks_sizeRR%t_post_alignRutticklabels_styleR!RR( RRjRRtdirRtlabelposRRRR}R ((s../src/biggles.pyt_make_ticklabelss$!   "cCs_|i|\}}|i||}|i||}|itt||f|idS(N(RRRR!Rt spine_style(RRjRRRR((s../src/biggles.pyt _make_spine0sc Cs|djpt|dj odSn|i|i}|i|t||i}g}x'|D]}|i|i||qeW|i t t ||f|dS(Ni( RRRRt_dposR9R]R%RRR!R( RRjRRR}Rtticklenttickposttick((s../src/biggles.pyt _make_ticks6s! cCs|iodSn|i|}|i||}|i||}|idjo|i}|idjo|idj p |i dj }|i o|i ||n|i oz|ip|o |i |||i|in|io |i |||i|in|io|i|q/n|ip|o|i|||n|idj oA|ittt|i|i|i|if|indS(N(t draw_nothingRRRt draw_subticksRRtdraw_ticklabelsRRt draw_gridt _make_gridt draw_axisRt subticks_sizetsubticks_styleRt ticks_stylet draw_spineRRR_RR!t _BoxLabelRRt_sideRt label_style(RRjRRRtimplicit_draw_subtickstimplicit_draw_ticklabels((s../src/biggles.pyRCs8          (R.R/RzRRRRRRRRRRR R(R+RRRRRRR(((s../src/biggles.pyRs&               t _HalfAxisXcBsSeZddZdZdZdZdZdZdZdZ RS( gcCs1|i||i|}|d|d|fS(Nii(R_t _intercept(RRjRtdbR((s../src/biggles.pyRmscCs d|fS(Ng((RRP((s../src/biggles.pyRqscCs |idjodSndSdS(NiRRR(scenterstop(scentersbottom(R(R((s../src/biggles.pyRtscCsX|idj o |iSn|i}|idjo|idSn|idSdS(Nii(RRR^RRe(RRjR((s../src/biggles.pyRzs   cCs"|idjo |iSn|iS(N(RRRE(RRj((s../src/biggles.pyRs cCs |idjodSndSdS(NiRR(R(R((s../src/biggles.pyRscCs|idj o|i\}}|djp |djoQ|ii\}}|djo |}n|djo |}n||fSq|iSn|iiS(N(RRR^Rd(RRjRRRORP((s../src/biggles.pyRs   cCsI|djodSnx-|D]%}|itt|f|iqWdS(N(RRR!Rt grid_style(RRjRR((s../src/biggles.pyRs  ( R.R/RRRRRRRR(((s../src/biggles.pyRks      t _HalfAxisYcBsSeZddZdZdZdZdZdZdZdZ RS( gcCs1|i|i||}|d||dfS(Nii(R_R(RRjRRR((s../src/biggles.pyRscCs |dfS(Ng((RRP((s../src/biggles.pyRscCs |idjodSndSdS(NiRRR(sleftscenter(srightscenter(R(R((s../src/biggles.pyRscCsX|idj o |iSn|i}|idjo|idSn|idSdS(Nii(RRR^RRd(RRjR((s../src/biggles.pyRs   cCs"|idjo |iSn|iS(N(RRRF(RRj((s../src/biggles.pyRs cCs |idjodSndSdS(NiRR(R(R((s../src/biggles.pyRscCs|idj o|i\}}|djp |djoQ|ii\}}|djo |}n|djo |}n||fSq|iSn|iiS(N(RRR^Re(RRjRRRORP((s../src/biggles.pyRs   cCsI|djodSnx-|D]%}|itt|f|iqWdS(N(RRR!RR(RRjRR((s../src/biggles.pyRs  ( R.R/RRRRRRRR(((s../src/biggles.pyRs      RcBs2eZhdd<ddRRR"R,R|((s../src/biggles.pyt _draw_textSs   cCsddk}|iido-|ii|ido|idSqn?ddddg}x)|D]!}|ii|o|SqeqeW|iS(se Intended for Windows, returns a valid temp directory, or at least the current working directory. iNtTEMPs\temps \winnt\temps \windows\temps\tmp(tostenvironRtpathtexiststgetcwd(Rtpossible_temp_pathsR((s../src/biggles.pyt win_temp_pathZs   t_PlotContainercBseZdZdZdZdZdZdZdZdddZ dZ d Z dd Z d Zd ZeZeZdddZdZRS(cKst|id|dS(NR(s_PlotContainer(R!R(RR"((s../src/biggles.pyR mscCsdS(N((R((s../src/biggles.pyRpsc CsNd}|i}|i}x#tdD]}|i||}t|i|i}t|i|i} t||} t| |} | |jo9| |jo,|idj o|i |in|Sn|i|i} t | |}t | | } t t |i|t |i| }q+WtdS(Ng{Gzt?i (RtdiagonalRtexteriorRRGRHtpt_lent aspect_ratioRtmake_aspect_ratioRRJRR0( RR>RtTOLtinteriortregion_diagonalRRtdlltdurtslltsurtscale((s../src/biggles.pyRss,   cCs |iS(N(R(RR>R((s../src/biggles.pyRscCs|idj ot|i|}|i||}|id}|id|}|ii}t |id|||dRRRRRR}((s../src/biggles.pytcompose_interiors  cCs|iotdn|i}|idj oJt|i|}t|id||}|i | |dddn|i ||}|i ||dS(Nsempty containerRqi( RR0RRRR9RRARtdeformRR(RR>tregionRRRqR((s../src/biggles.pytcomposes  cCs|it|i|i}|i|_x3tidiD]\}}|i ||qDW|i |i |i |||i dS(NR:(RRJRGRHRR5R<RRwRftexpandt page_marginRR(RR>RR,R|((s../src/biggles.pyt page_composes  cCsddk}|djotidd}n|djotidd}n|idjo|i||nF|idjp|idjo|i||ntd|idS( NitscreenR1R2tposixtdostnts$show: system type '%s' not supported(RRR<R*R'tshow_x11tshow_winR (RR1R2R((s../src/biggles.pytshows    cCsOtiotidd}ti|||}|i||idS(NRt persistent(R<t interactivetbooltrenderertScreenRendererRtdelete(RR1R2RR>((s../src/biggles.pyRs   cCsKddk}ddk}|id}|i||||i|dS(s Substitute for show() that will work on Windows. Generates temporary files somewhere that end with '_biggles.png'. These temporary files are not deleted, they must be manually cleaned up during normal temp directory maintenance. iNs _biggles.png(Rttempfiletmktempt write_imgt startfile(RR1R2RRttf((s../src/biggles.pyRscKsddk}ddk}|idjotd|in|djotidd}n|itid}|i|td||i |d}t t i |f|}|i ||i|idS( NiRs'psprint: system type '%s' not supportedtprintertcommandt postscriptsprinting plot with "%s"R6(RRR'R RR<R*RRutpopenR!Rt PSRendererRRR(RtprintcmdR"RRtoptR R>((s../src/biggles.pytpsprints    cKsntitid}|i|t|}tti|f|}|i||i t |dS(NR ( RR<RRuRR!RRRRR(RRR"RRR>((s../src/biggles.pyt write_epss    c Gst|djo|\}}}}nFt|djo2ddk}|\}}}|i|d}nt|}ti||||}|i||it|dS(Niiii( RRtlowerRRt ImageRendererRRR( RRRR1R2RRRR>((s../src/biggles.pyRs    icCsCddkl}|||}|i||i}|i|S(Ni(tPiddleRenderer(t device.piddleRRtcanvasR(Rt canvastypeRRR>R((s../src/biggles.pyt draw_piddles    c Gsddk}ddk}t|djo|\}}nd}|id}|i||||t|d}|i} |i|i|| S(s> Saves PNG file in temporary file. Returns file contents. iNitpngs _biggles.pngtrb( RRRRRRtreadRtremove( RRRRR1R2RRtftoutput((s../src/biggles.pytwrite_back_png s   N(ii(R.R/R RRRRRRRRRRRRRt save_as_epst save_as_imgRR!(((s../src/biggles.pyRks"        cKst|}titid}|i|tti|f|}x|D]}|i|qPW|i t |dS(NR ( RRR<RRuR!RRRRR(tplotsRR"RRR>tplot((s../src/biggles.pyt multipages   c Cs'd\}}|dj o>|\}}|dj o |}n|dj o |}qWn|dj oId|||}||}| p |djo |}n||}n|dj o>|\}}|dj o |}n|dj o |}qn||jo|d}|d}n||fS(Niig?(ii(R( t content_rangetguttert user_rangeRRttr1RRtdx((s../src/biggles.pyt _limits_axis)s.              cCs_t|i|||}t|i|||}t|d|df|d|dfS(Nii(R,RdReRJ(t content_bboxR(RERFRdReRgRh((s../src/biggles.pyt_limitsDstPlotcBsMeZdZdZdZdZdZddZddZ RS(cKs6tti|ft|id|t|_dS(NR/(sPlot(R!RR RRtcontent(RR"((s../src/biggles.pyR OscCs|i|dS(N(R(Rtother((s../src/biggles.pyt__iadd__TscCs |iiS(N(R0R(R((s../src/biggles.pyRWscGst|ii|dS(N(R!R0R(RR((s../src/biggles.pyRZscCs1t|ii|i|i|i|i|iS(N(R.R0RR(RERFRdRe(R((s../src/biggles.pyR]scCsU|djo|i}nt|||d|id|i}|ii|dS(NRERF(RRR[RERFR0R(RR>RRRj((s../src/biggles.pyRas  cCs)|i||}|i|||dS(N(RR(RR>RRR((s../src/biggles.pyRhsN( R.R/R R2RRRRRR(((s../src/biggles.pyR/Ms      t FramedPlotcBseZdZhdd<dd<dd<dd<dd <d d <d!d <d"d ((R((s../src/biggles.pyt__repr__scCsn|ii|oL|i|}|}x!|d D]}t||}q1Wt||dSn |i|SdS(Ni(RRR&R(RR'txsR#R((s../src/biggles.pyR(s  cCss|ii|oO|i|}|}x!|d D]}t||}q1Wt||d|n||i|R#R((s../src/biggles.pyR+s  cCs|iio |iiS(N(R4RR5(R((s../src/biggles.pyRscGst|ii|dS(N(R!R4R(RR((s../src/biggles.pyRscGst|ii|dS(N(R!R5R(RR((s../src/biggles.pytadd2scCs4t|ii|iit|ii|iifS(N(RR7RR,R8R-(R((s../src/biggles.pyt_xy2logscCs=t|ii|i|ii|ii|ii|iiS(N(R.R4RR(R,RR-R(R((s../src/biggles.pyt_limits1scCs.t|||id|iid|iiS(NRERF(R[RAR,RR-(RR>R((s../src/biggles.pyt _context1scCs|ii}|iio|ii}n|i\}}t|ii|ii}t|i i|i i}t ||i ||||S(N( R5RRR4R@RR7RR,R8R-R.R((RRRERFRdRe((s../src/biggles.pyt_limits2scCs.|i\}}t|||i||S(N(R@R[RC(RR>RRERF((s../src/biggles.pyt _context2scCst}|i||}|i|ii||i|ii||i||}|i|ii||i|ii||S(N( RJRBRR,R5R-RDR7R8(RR>RR5tcontext1tcontext2((s../src/biggles.pyRs cCsti||||i||}|i||}|ii||ii||ii||ii||i i||i i|dS(N( RRRBRDR4RR5R8R7R-R,(RR>RRERF((s../src/biggles.pyRs(sx1slabel(sy1slabel(sx1slog(sy1slog(sx1srange(sy1srange(sx1slabel(sy1slabel(R.R/R RR=R(R+RRR?R@RARBRCRDRR(((s../src/biggles.pyR3ns.                  tOldCustomFramedPlotcBseZdZRS(cKs2tti|f||i|_|i|_dS(N(R!R3R R,RR-R(RR"((s../src/biggles.pyR s (R.R/R (((s../src/biggles.pyRGst_GridcBs eZdddZdZRS(ic Cs||_||_|i|i}}t||}t||} t|i||f|_|| ||_|| ||_ |i| d||i | d|f|_ dS(Ni( tnrowstncolsR1R2R9RRGRststep_xtstep_yt cell_dimen( RRIRJR5t cellpaddingt cellspacingR6R7tcptcs((s../src/biggles.pyR s  cCsV|id|}t|i||i||if}t||i}t||S(Ni(RIRRsRKRLRMRJ(RRRtiiRR((s../src/biggles.pytcells&(R.R/R RS(((s../src/biggles.pyRHstTablecBsGeZdZdZdZdZdZdZdZRS(cKsEtti|ft|id|||_||_h|_dS(NRT(sTable(R!RR RtrowstcolsR0(RRURVR"((s../src/biggles.pyR  s   cCs |i|S(N(R0(RR,((s../src/biggles.pyt __getitem__ scCs||i|RtexttgR,R#t subregion((s../src/biggles.pyR s   !cCsti|||t|i|i||i|i}x]|iiD]L\}}t |i |}|i o|i||qG|i ||qGWdS(N( RRRHRURVRNROR0RwR!RSRXR(RR>RRZR,R#R[((s../src/biggles.pyR% s  ( R.R/R RWR-RfR{RR(((s../src/biggles.pyRT s      cCsDtd|}t|||d|id|i}|i|dS(NRRERF(RR[RERFR(R#R>RRRR6Rj((s../src/biggles.pyt _frame_draw7 scCs@td|}t|||d|id|i}|i|S(NRRERF(RR[RERFR5(R#R>RRRR6Rj((s../src/biggles.pyt _frame_bbox= scCsV|djo|Sn|djo|Snt|d|dt|d|dfS(Nii(RRR=(RR((s../src/biggles.pyt _range_unionC s   t FramedArraycBseZdZdddddgZhdd<dd RRRZtcornersR,R#R[Rt axislabels((s../src/biggles.pyt _frames_bbox s    cCs|i||}t|i|}t|i||}||}|idj o|id|ddn|idj o|idd|dn|S(Ni( RnR9RRAR`R9RRR:(RR>RRRRatmargin((s../src/biggles.pyR s c Cs|i|}x|iiD]\}}t|i|}t|i|}ddddg}|d|idjod|dRRZR,R#R[RRm((s../src/biggles.pyt _frames_draw s  cCsj|i|}xT|iiD]C\}}t|i|}t|i|}|i|||qWdS(N(RkR0RwR!RSR.R(RR>RRZR,R#R[R((s../src/biggles.pyt _data_draw s  cCsC|i||}t|i|}t|i||}|i|id||idd|idj oQ|i d}|i d|}|idd|i ||f|in|i dj oa|i d|}|i d}|idd |idd |i ||f|i n|idS( NRqRRiRRiRgV@R(RnR9RRAR`RRfR9RRReRR:RdR(RR>RRRRaRR((s../src/biggles.pyt _labels_draw s& cGs.x'|iiD]}t|i|qWdS(N(R0RR!R(RRR#((s../src/biggles.pyR scCsGti||||i|||i|||i||dS(N(RRRqRpRr(RR>R((s../src/biggles.pyR s(R.R/R RbRcR+RWR.RfRgRkRnRRpRqRrRR(((s../src/biggles.pyR_H s,               tTextcBseZdZdZRS(cKstti|ft|id|ddk}|i|d|_|iddjo|id=n|iddjo|id=ndS(NRsis iR`(sText(R!RR RRRtlines(RRR"R((s../src/biggles.pyR s c Cs4|it|||}t|i|i|}|id|d}x)|iD]}t||i|}qTW||i }||t |id}|i \} } | |d} |i djo| |i |d} n-|i djo| |i |d} n|idjo| |i|d} n-|idjo| |i|d} n|idjo| |d } n#|idjo| |d } nt} | } xU|iD]J}| it| | |d |id dd |id|i| |} qW| i||idS( NRqiig@RRRRiRRR(RR[RARqR]RfRtR=Rt lineheightRRRR1RR2tjustifyRRRRRR( RR>RRjRqtblock_wRtdytblock_hR RtblockR((s../src/biggles.pyR sH        (R.R/R R(((s../src/biggles.pyRs s t_InsetcBseZdZdZRS(cCst|||_||_dS(N(RJt plot_limitsR%(RRRR%((s../src/biggles.pyR  scCs)|i|}|ii|i|dS(N(R5R%RR\(RRjR((s../src/biggles.pyR# s(R.R/R R(((s../src/biggles.pyR{ s t DataInsetcBseZdZdZRS(cCsCt|i|ii}t|i|ii}t||S(N(R!R_R|RGRHRJ(RRjRR((s../src/biggles.pyR5) scCs |iiS(N(R|R(R((s../src/biggles.pyR. s(R.R/R5R(((s../src/biggles.pyR}' s t PlotInsetcBseZdZdZRS(cCsCt|i|ii}t|i|ii}t||S(N(R!R`R|RGRHRJ(RRjRR((s../src/biggles.pyR53 scCstS(N(RJ(R((s../src/biggles.pyR8 s(R.R/R5R(((s../src/biggles.pyR~1 s (ii((((((((iiii(iiii((RRRRRTR<Rtgeometrytlibplot.renderertlibplotRt_truet_falseRRR R RRRt ExceptionR0R9RARBR[RlRmRoRpRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR$R%R&R'R(R)R*R.R1R4R6R;R<RCRIRLRMRNRRRTRRZR[R\R]RjRoRqRuRvRwRzRRRRRRRRRRRRRRRRRR&R,R.R/R3RGRHRTR\R]R^R_RsR{R}R~(((s../src/biggles.pyss0            %   1 07 ' %%        +   /         57&,      !w 3   ;  python2-biggles-1.6.6/src/biggles.py0000755000175100017510000020220011113636574016342 0ustar noltanolta# # $Id: biggles.py,v 1.235 2008/11/28 00:38:20 mrnolta Exp $ # # Copyright (C) 2000-2008 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import copy, math, os, string import numpy import config, _biggles from geometry import * import libplot.renderer renderer = libplot.renderer # miscellaneous --------------------------------------------------------------- _true, _false = 1, 0 def _floor(x): return long(math.floor(x)) def _ceil(x): return long(math.ceil(x)) def _tsil(x): l = list(x) l.reverse() return l def _message( s ): print "biggles:", s def _series( m, n, a=1, b=0 ): return map( lambda x,y=a,z=b: x*y+z, range(m, n+1) ) def _first_not_none( *args ): for arg in args: if arg is not None: return arg return None class _Alias: def __init__( self, *args ): self.__dict__["objs"] = args[:] def __call__( self, *args, **kw ): for obj in self.objs: apply( obj, args, kw ) def __getattr__( self, name ): objs = [] for obj in self.objs: objs.append( getattr(obj, name) ) return apply( _Alias, objs ) def __setattr__( self, name, value ): for obj in self.objs: setattr( obj, name, value ) def __setitem__( self, key, value ): for obj in self.objs: obj[key] = value # BigglesError ---------------------------------------------------------------- class BigglesError( Exception ): pass # relative size --------------------------------------------------------------- def _size_relative( relsize, bbox ): w = bbox.width() h = bbox.height() yardstick = math.sqrt(8) * w * h / (w + h) return (relsize/100.) * yardstick def _fontsize_relative( relsize, bbox, device ): devsize = _size_relative( relsize, bbox ) devsize_min = _size_relative( config.value('default','fontsize_min'), device.bbox ) return max( devsize, devsize_min ) # _PlotContext ----------------------------------------------------------------- class _PlotGeometry: _logfunc = math.log10 _logfunc_vec = numpy.log10 def __init__( self, src, dest, xlog=0, ylog=0 ): self.src_bbox = src self.dest_bbox = dest self.xlog = xlog self.ylog = ylog a, b = src.lowerleft() c, d = src.upperright() if xlog: a = self._logfunc(a) c = self._logfunc(c) if ylog: b = self._logfunc(b) d = self._logfunc(d) fsrc = BoundingBox( (a,b), (c,d) ) self.aff = RectilinearMap( fsrc, dest ) def __call__( self, x, y ): u, v = x, y if self.xlog: u = self._logfunc(x) if self.ylog: v = self._logfunc(y) return self.aff( u, v ) def call_vec( self, x, y ): u = numpy.asarray( x ) v = numpy.asarray( y ) if self.xlog: u = self._logfunc_vec(u) if self.ylog: v = self._logfunc_vec(v) return self.aff.call_vec( u, v ) def geodesic( self, x, y, div=1 ): return [(x, y)] class _PlotContext: def __init__( self, device, dev, data, xlog=0, ylog=0 ): self.draw = device self.dev_bbox = dev self.data_bbox = data self.xlog = xlog self.ylog = ylog self.geom = _PlotGeometry( data, dev, xlog=xlog, ylog=ylog ) self.plot_geom = _PlotGeometry( BoundingBox((0,0),(1,1)), dev ) def do_clip( self ): xr = self.dev_bbox.xrange() yr = self.dev_bbox.yrange() self.draw.set( "cliprect", (xr[0], xr[1], yr[0], yr[1]) ) # _StyleKeywords -------------------------------------------------------------- def _kw_func_relative_fontsize( context, key, value ): device_size = _fontsize_relative( value, context.dev_bbox, context.draw ) context.draw.set( key, device_size ) def _kw_func_relative_size( context, key, value ): device_size = _size_relative( value, context.dev_bbox ) context.draw.set( key, device_size ) def _kw_func_relative_width( context, key, value ): device_width = _size_relative( value/10., context.dev_bbox ) context.draw.set( key, device_width ) class _StyleKeywords: kw_style = None kw_defaults = {} kw_rename = {} kw_func = { 'fontsize' : _kw_func_relative_fontsize, 'linewidth' : _kw_func_relative_width, 'symbolsize' : _kw_func_relative_size, } def kw_init( self, kw=None ): self.kw_style = {} self.kw_style.update( self.kw_defaults ) if kw is not None: for key, value in kw.items(): self.kw_set( key, value ) def kw_set( self, key, value ): if self.kw_style is None: self.kw_init() key = self.kw_rename.get( key, key ) self.kw_style[key] = value def style( self, **kw ): for key,val in kw.items(): self.kw_set( key, val ) def kw_get( self, key, notfound=None ): if self.kw_style is not None: return self.kw_style.get( key, notfound ) else: return None def kw_predraw( self, context ): context.draw.save_state() if self.kw_style is not None: for key, value in self.kw_style.items(): if self.kw_func.has_key(key): method = self.kw_func[key] apply( method, (context,key,value) ) else: context.draw.set( key, value ) def kw_postdraw( self, context ): context.draw.restore_state() # _ConfAttributes ----------------------------------------------------------- class _ConfAttributes: def conf_setattr( self, section, **kw ): import copy, string sec = config.options( section ) if sec is not None: for key,val in sec.items(): x = string.split( key, "." ) obj = self for y in x[:-1]: obj = getattr( obj, y ) setattr( obj, x[-1], copy.copy(val) ) for key,val in kw.items(): setattr( self, key, copy.copy(val) ) # _DeviceObject --------------------------------------------------------------- class _DeviceObject( _StyleKeywords ): def bbox( self, context ): return BoundingBox() def draw( self, context ): raise BigglesError def render( self, context ): self.kw_predraw( context ) self.draw( context ) self.kw_postdraw( context ) class _SymbolObject( _DeviceObject ): kw_rename = { 'type' : 'symboltype', 'size' : 'symbolsize', } def __init__( self, pos, **kw ): self.kw_init( kw ) self.pos = pos def bbox( self, context ): self.kw_predraw( context ) symbolsize = context.draw.get( 'symbolsize' ) self.kw_postdraw( context ) dp = symbolsize/2, symbolsize/2 p = pt_sub( self.pos, dp ) q = pt_add( self.pos, dp ) return BoundingBox( p, q ) def draw( self, context ): context.draw.symbol( self.pos ) class _TextObject( _DeviceObject ): kw_defaults = { 'textangle' : 0, 'texthalign' : 'center', 'textvalign' : 'center', } kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', 'angle' : 'textangle', 'halign' : 'texthalign', 'valign' : 'textvalign', } def __init__( self, pos, str, **kw ): self.kw_init( kw ) self.pos = pos self.str = str __halign_offset = { 'right':(-1,0), 'center':(-.5,.5), 'left':(0,1) } __valign_offset = { 'top':(-1,0), 'center':(-.5,.5), 'bottom':(0,1) } def bbox( self, context ): self.kw_predraw( context ) angle = context.draw.get( 'textangle' ) * math.pi/180. halign = context.draw.get( 'texthalign' ) valign = context.draw.get( 'textvalign' ) width = context.draw.textwidth( self.str ) height = context.draw.textheight( self.str ) self.kw_postdraw( context ) hvec = pt_mul( width, _TextObject.__halign_offset[halign] ) vvec = pt_mul( height, _TextObject.__valign_offset[valign] ) p = self.pos[0] + hvec[0], self.pos[1] + vvec[0] q = self.pos[0] + hvec[1], self.pos[1] + vvec[1] bb = BoundingBox( p, q ) bb.rotate( angle, self.pos ) return bb def draw( self, context ): #bb = self.bbox( context ) #context.draw.rect( bb.lowerleft(), bb.upperright() ) context.draw.text( self.pos, self.str ) class _LabelsObject( _DeviceObject ): kw_defaults = { 'textangle' : 0, 'texthalign' : 'center', 'textvalign' : 'center', } kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', 'angle' : 'textangle', 'halign' : 'texthalign', 'valign' : 'textvalign', } def __init__( self, points, labels, **kw ): self.kw_init( kw ) self.points = points self.labels = labels __halign_offset = { 'right':(-1,0), 'center':(-.5,.5), 'left':(0,1) } __valign_offset = { 'top':(-1,0), 'center':(-.5,.5), 'bottom':(0,1) } def bbox( self, context ): bb = BoundingBox() self.kw_predraw( context ) angle = context.draw.get( 'textangle' ) * math.pi/180. halign = context.draw.get( 'texthalign' ) valign = context.draw.get( 'textvalign' ) height = context.draw.textheight( self.labels[0] ) ho = _LabelsObject.__halign_offset[halign] vo = _LabelsObject.__valign_offset[valign] for i in range(len(self.labels)): pos = self.points[i] width = context.draw.textwidth( self.labels[i] ) p = pos[0] + width * ho[0], pos[1] + height * vo[0] q = pos[0] + width * ho[1], pos[1] + height * vo[1] bb_label = BoundingBox( p, q ) if angle != 0: bb_label.rotate( angle, pos ) bb.union( bb_label ) self.kw_postdraw( context ) return bb def draw( self, context ): for i in range(len(self.labels)): context.draw.text( self.points[i], self.labels[i] ) class _LineTextObject( _TextObject ): kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', } def __init__( self, p, q, str, offset, **kw ): self.kw_init( kw ) self.str = str midpoint = pt_mul( 0.5, pt_add(p, q) ) direction = pt_unit( pt_sub(q, p) ) angle = pt_angle( direction ) direction = pt_rot( direction, math.pi/2 ) self.pos = pt_add( midpoint, pt_mul(offset, direction) ) self.kw_set( 'textangle', angle * 180./math.pi ) self.kw_set( 'texthalign', 'center' ) if offset > 0: self.kw_set( 'textvalign', 'bottom' ) else: self.kw_set( 'textvalign', 'top' ) class _LineObject( _DeviceObject ): kw_rename = { 'width' : 'linewidth', 'type' : 'linetype', } def __init__( self, p, q, **kw ): self.kw_init( kw ) self.p = p self.q = q def bbox( self, context ): return BoundingBox( self.p, self.q ) def draw( self, context ): context.draw.line( self.p, self.q ) class _PolygonObject( _DeviceObject ): kw_rename = { 'width' : 'linewidth', 'type' : 'linetype', } def __init__( self, points, **kw ): self.kw_init( kw ) self.points = points def bbox( self, context ): return apply( BoundingBox, self.points ) def draw( self, context ): context.draw.polygon( self.points ) class _PathObject( _DeviceObject ): kw_rename = { 'width' : 'linewidth', 'type' : 'linetype', } def __init__( self, x, y, **kw ): self.kw_init( kw ) self.x = x self.y = y def bbox( self, context ): xmin, xmax = _biggles.range( self.x ) ymin, ymax = _biggles.range( self.y ) return BoundingBox( (xmin,ymin), (xmax,ymax) ) def draw( self, context ): context.draw.curve( self.x, self.y ) class _SymbolsObject( _DeviceObject ): kw_rename = { 'type' : 'symboltype', 'size' : 'symbolsize', } def __init__( self, x, y, **kw ): self.kw_init( kw ) self.x = x self.y = y def bbox( self, context ): xmin, xmax = _biggles.range( self.x ) ymin, ymax = _biggles.range( self.y ) return BoundingBox( (xmin,ymin), (xmax,ymax) ) def draw( self, context ): context.draw.symbols( self.x, self.y ) class _ColoredSymbolsObject( _DeviceObject ): kw_rename = { 'type' : 'symboltype', 'size' : 'symbolsize', } def __init__( self, x, y, c, **kw ): self.kw_init( kw ) self.x = x self.y = y self.c = c def bbox( self, context ): xmin, xmax = _biggles.range( self.x ) ymin, ymax = _biggles.range( self.y ) return BoundingBox( (xmin,ymin), (xmax,ymax) ) def draw( self, context ): context.draw.colored_symbols( self.x, self.y, self.c ) class _DensityObject( _DeviceObject ): kw_rename = { } def __init__( self, densgrid, ((xmin,ymin), (xmax,ymax)), **kw ): self.kw_init( kw ) self.densgrid = densgrid self.extent = ( (xmin,ymin), (xmax,ymax) ) def bbox( self, context ): return apply( BoundingBox, self.extent ) def draw( self, context ): #from numpy import rank #if rank(self.densgrid) == 3: if len(self.densgrid.shape) == 3: context.draw.color_density_plot( self.densgrid, self.extent ) else: context.draw.density_plot( self.densgrid, self.extent ) class _EllipseObject( _DeviceObject ): def __init__( self, p, rx, ry, angle=0., **kw ): self.kw_init( kw ) self.p = p self.rx = rx self.ry = ry self.angle = angle def bbox( self, context ): r = self.rx, self.ry p = pt_add( self.p, r ) q = pt_sub( self.p, r ) bb = BoundingBox( p, q ) bb.rotate( self.p, self.angle ) return bb def draw( self, context ): context.draw.ellipse( self.p, self.rx, self.ry, self.angle ) class _CombObject( _DeviceObject ): def __init__( self, points, dp, **kw ): self.kw_init( kw ) self.points = points self.dp = dp def bbox( self, context ): return apply( BoundingBox, self.points ) def draw( self, context ): for p in self.points: context.draw.move( p ) context.draw.linetorel( self.dp ) class _BoxObject( _DeviceObject ): def __init__( self, p, q, **kw ): self.kw_init( kw ) self.p = p self.q = q def bbox( self, context ): return BoundingBox( self.p, self.q ) def draw( self, context ): context.draw.rect( self.p, self.q ) class _ArcObject( _DeviceObject ): def __init__( self, pc, p0, p1, **kw ): self.kw_init( kw ) self.pc = pc self.p0 = p0 self.p1 = p1 def bbox( self, context ): return BoundingBox( self.pc, self.p0, self.p1 ) def draw( self, context ): context.draw.arc( self.pc, self.p0, self.p1 ) # _PlotComponent -------------------------------------------------------------- class _PlotComponent( _StyleKeywords, _ConfAttributes ): def __init__( self ): self.clear() def add( self, *args ): for obj in args: self.device_objects.append( obj ) def limits( self ): return BoundingBox() def clear( self ): self.device_objects = [] def make( self, context ): raise BigglesError def make_key( self, bbox ): pass def bbox( self, context ): self.clear() self.make( context ) bb = BoundingBox() for obj in self.device_objects: bb.union( obj.bbox(context) ) return bb def render( self, context ): self.clear() self.make( context ) self.kw_predraw( context ) for obj in self.device_objects: obj.render( context ) self.kw_postdraw( context ) # _LabelComponent ------------------------------------------------------------- class _LabelComponent( _PlotComponent ): kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', 'angle' : 'textangle', 'halign' : 'texthalign', 'valign' : 'textvalign', } def __init__( self, x, y, str, **kw ): _PlotComponent.__init__( self ) self.conf_setattr( "_LabelComponent" ) self.kw_init( kw ) self.pos = x, y self.str = str def limits( self ): return BoundingBox() class DataLabel( _LabelComponent ): def make( self, context ): pos = apply( context.geom, self.pos ) t = apply( _TextObject, (pos, self.str), self.kw_style ) self.add( t ) class PlotLabel( _LabelComponent ): def make( self, context ): pos = apply( context.plot_geom, self.pos ) t = apply( _TextObject, (pos, self.str), self.kw_style ) self.add( t ) # _LabelsComponent ------------------------------------------------------------ class _LabelsComponent( _PlotComponent ): kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', 'angle' : 'textangle', 'halign' : 'texthalign', 'valign' : 'textvalign', } def __init__( self ): _PlotComponent.__init__( self ) self.conf_setattr( "_LabelsComponent" ) class Labels( _LabelsComponent ): def __init__( self, x, y, labels, **kw ): _LabelsComponent.__init__( self ) self.conf_setattr( "Labels" ) self.kw_init( kw ) self.x = x self.y = y self.labels = labels def limits( self ): p = min(self.x), min(self.y) q = max(self.x), max(self.y) return BoundingBox( p, q ) def make( self, context ): x, y = context.geom.call_vec( self.x, self.y ) l = apply( _LabelsObject, (zip(x,y), self.labels), self.kw_style ) self.add( l ) # _LineComponent -------------------------------------------------------------- class _LineComponent( _PlotComponent ): def __init__( self ): _PlotComponent.__init__( self ) self.conf_setattr( "_LineComponent" ) kw_rename = { 'color' : 'linecolor', 'width' : 'linewidth', 'type' : 'linetype', } def make_key( self, bbox ): xr = bbox.xrange() y = bbox.center()[1] p = xr[0], y q = xr[1], y return apply( _LineObject, (p,q), self.kw_style ) class Curve( _LineComponent ): def __init__( self, x, y, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "Curve" ) self.kw_init( kw ) self.x = x self.y = y def limits( self ): p0 = min(self.x), min(self.y) p1 = max(self.x), max(self.y) return BoundingBox( p0, p1 ) def make( self, context ): segs = context.geom.geodesic( self.x, self.y ) for seg in segs: x, y = context.geom.call_vec( seg[0], seg[1] ) self.add( _PathObject(x, y) ) class DataLine( _LineComponent ): def __init__( self, p, q, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "DataLine" ) self.kw_init( kw ) self.p = p self.q = q def limits( self ): return BoundingBox( self.p, self.q ) def make( self, context ): a = apply( context.geom, self.p ) b = apply( context.geom, self.q ) self.add( _LineObject(a, b) ) class Geodesic( _LineComponent ): def __init__( self, p, q, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "Geodesic" ) self.kw_init( kw ) self.p = p self.q = q def limits( self ): return BoundingBox( self.p, self.q ) def make( self, context ): l = self.p[0], self.q[0] b = self.p[1], self.q[1] segs = context.geom.geodesic( l, b, self.divisions ) for seg in segs: x, y = context.geom.call_vec( seg[0], seg[1] ) self.add( _PathObject(x, y) ) class Histogram( _LineComponent ): def __init__( self, values, x0=0, binsize=1, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "Histogram" ) self.kw_init( kw ) self.values = values self.x0 = x0 self.binsize = binsize def limits( self ): nval = len( self.values ) if self.drop_to_zero: p = self.x0, min( 0, min(self.values) ) else: p = self.x0, min(self.values) q = self.x0 + nval*self.binsize, max(self.values) return BoundingBox( p, q ) def make( self, context ): nval = len( self.values ) x = [] y = [] if self.drop_to_zero: x.append( self.x0 ) y.append( 0 ) for i in range(0,nval): xi = self.x0 + i * self.binsize yi = self.values[i] x.extend( [xi, xi + self.binsize] ) y.extend( [yi, yi] ) if self.drop_to_zero: x.append( self.x0 + nval*self.binsize ) y.append( 0 ) u, v = context.geom.call_vec( x, y ) self.add( _PathObject(u, v) ) class LineX( _LineComponent ): def __init__( self, x, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "LineX" ) self.kw_init( kw ) self.x = x def limits( self ): return BoundingBox( (self.x,None), (self.x,None) ) def make( self, context ): yrange = context.data_bbox.yrange() p = self.x, yrange[0] q = self.x, yrange[1] a = apply( context.geom, p ) b = apply( context.geom, q ) self.add( _LineObject(a, b) ) class LineY( _LineComponent ): def __init__( self, y, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "LineY" ) self.kw_init( kw ) self.y = y def limits( self ): return BoundingBox( (None,self.y), (None,self.y) ) def make( self, context ): xrange = context.data_bbox.xrange() p = xrange[0], self.y q = xrange[1], self.y a = apply( context.geom, p ) b = apply( context.geom, q ) self.add( _LineObject(a, b) ) class PlotLine( _LineComponent ): def __init__( self, p, q, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "PlotLine" ) self.kw_init( kw ) self.p = p self.q = q def make( self, context ): a = apply( context.plot_geom, self.p ) b = apply( context.plot_geom, self.q ) self.add( _LineObject(a, b) ) class Slope( _LineComponent ): def __init__( self, slope, intercept=None, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "Slope" ) self.kw_init( kw ) self.slope = slope self.intercept = intercept if intercept is None: self.intercept = (0.,0.) def _x( self, y ): x0, y0 = self.intercept return x0 + float(y - y0) / self.slope def _y( self, x ): x0, y0 = self.intercept return y0 + (x - x0) * self.slope def make( self, context ): xrange = context.data_bbox.xrange() yrange = context.data_bbox.yrange() if self.slope == 0: l = [ ( xrange[0], self.intercept[1] ),\ ( xrange[1], self.intercept[1] ) ] else: l = [ ( xrange[0], self._y(xrange[0]) ),\ ( xrange[1], self._y(xrange[1]) ),\ ( self._x(yrange[0]), yrange[0] ),\ ( self._x(yrange[1]), yrange[1] ) ] m = filter( context.data_bbox.contains, l ) m.sort() if len(m) > 1: a = apply( context.geom, m[0] ) b = apply( context.geom, m[-1] ) self.add( _LineObject(a, b) ) class DataBox( _LineComponent ): def __init__( self, p, q, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "DataBox" ) self.kw_init( kw ) self.p = p self.q = q def limits( self ): return BoundingBox( self.p, self.q ) def make( self, context ): a = apply( context.geom, self.p ) b = apply( context.geom, self.q ) self.add( _BoxObject(a, b) ) class PlotBox( _LineComponent ): def __init__( self, p, q, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "PlotBox" ) self.kw_init( kw ) self.p = p self.q = q def make( self, context ): a = apply( context.plot_geom, self.p ) b = apply( context.plot_geom, self.q ) self.add( _BoxObject(a, b) ) class PlotArc( _LineComponent ): def __init__( self, pc, r, a0, a1, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "PlotArc" ) self.kw_init( kw ) self.pc = pc self.p0 = p[0] + r*math.cos(a0), p[1] + r*math.sin(a0) self.p1 = p[0] + r*math.cos(a1), p[1] + r*math.sin(a1) def make( self, context ): pc = apply( context.plot_geom, self.pc ) p0 = apply( context.plot_geom, self.p0 ) p1 = apply( context.plot_geom, self.p1 ) self.add( _ArcObject(pc, p0, p1) ) class DataArc( _LineComponent ): def __init__( self, pc, r, a0, a1, **kw ): _LineComponent.__init__( self ) self.conf_setattr( "DataArc" ) self.kw_init( kw ) self.pc = pc self.p0 = p[0] + r*math.cos(a0), p[1] + r*math.sin(a0) self.p1 = p[0] + r*math.cos(a1), p[1] + r*math.sin(a1) def limits( self ): return BoundingBox( self.pc, self.p0, self.p1 ) def make( self, context ): pc = apply( context.geom, self.pc ) p0 = apply( context.geom, self.p0 ) p1 = apply( context.geom, self.p1 ) self.add( _ArcObject(pc, p0, p1) ) # _SymbolDataComponent -------------------------------------------------------- class _SymbolDataComponent( _PlotComponent ): kw_rename = { 'type' : 'symboltype', 'size' : 'symbolsize', } def make_key( self, bbox ): pos = bbox.center() return apply(_SymbolObject, (pos,), self.kw_style) class Points( _SymbolDataComponent ): kw_defaults = { 'symboltype' : config.value('Points','symboltype'), 'symbolsize' : config.value('Points','symbolsize'), } def __init__( self, x, y, **kw ): _SymbolDataComponent.__init__( self ) self.conf_setattr( "Points" ) self.kw_init( kw ) self.x = x self.y = y def limits( self ): p = min(self.x), min(self.y) q = max(self.x), max(self.y) return BoundingBox( p, q ) def make( self, context ): x, y = context.geom.call_vec( self.x, self.y ) self.add( _SymbolsObject(x, y) ) def Point( x, y, **kw ): return apply( Points, ([x],[y]), kw ) class ColoredPoints( _SymbolDataComponent ): kw_defaults = { 'symboltype' : config.value('Points','symboltype'), 'symbolsize' : config.value('Points','symbolsize'), } def __init__( self, x, y, c=None, **kw ): _SymbolDataComponent.__init__( self ) self.conf_setattr( "Points" ) self.kw_init( kw ) self.x = x self.y = y self.c = c def limits( self ): p = min(self.x), min(self.y) q = max(self.x), max(self.y) return BoundingBox( p, q ) def make( self, context ): x, y = context.geom.call_vec( self.x, self.y ) self.add( _ColoredSymbolsObject(x, y, self.c) ) def ColoredPoint( x, y, **kw ): return apply( ColoredPoints, ([x],[y]), kw ) # _DensityComponent ----------------------------------------------------------- class Density( _PlotComponent ): kw_defaults = { 'foo' : config.value('Points','symbolsize'), } def __init__( self, densgrid, ((xmin,ymin), (xmax,ymax)), **kw ): _PlotComponent.__init__( self ) self.conf_setattr( "Density" ) self.kw_init( kw ) self.densgrid = densgrid self.extent = ((xmin,ymin), (xmax,ymax)) def limits( self ): return apply( BoundingBox, self.extent ) def make( self, context ): (x0,y0),(x1,y1) = self.extent (x0,x1),(y0,y1) = context.geom.call_vec((x0,x1),(y0,y1)) self.add( _DensityObject(self.densgrid, ((x0,y0),(x1,y1))) ) # _FillComponent -------------------------------------------------------------- class _FillComponent( _PlotComponent ): kw_defaults = { 'color' : config.value('_FillComponent','fillcolor'), 'filltype' : config.value('_FillComponent','filltype'), } def make_key( self, bbox ): p = bbox.lowerleft() q = bbox.upperright() return apply( _BoxObject, (p,q), self.kw_style ) class FillAbove( _FillComponent ): def __init__( self, x, y, **kw ): _FillComponent.__init__( self ) self.conf_setattr( "FillAbove" ) self.kw_init( kw ) self.x = x self.y = y def limits( self ): p = min(self.x), min(self.y) q = max(self.x), max(self.y) return BoundingBox( p, q ) def make( self, context ): coords = map( context.geom, self.x, self.y ) max_y = context.data_bbox.yrange()[1] coords.append( context.geom(self.x[-1], max_y) ) coords.append( context.geom(self.x[0], max_y) ) self.add( _PolygonObject(coords) ) class FillBelow( _FillComponent ): def __init__( self, x, y, **kw ): _FillComponent.__init__( self ) self.conf_setattr( "FillBelow" ) self.kw_init( kw ) self.x = x self.y = y def limits( self ): p = min(self.x), min(self.y) q = max(self.x), max(self.y) return BoundingBox( p, q ) def make( self, context ): coords = map( context.geom, self.x, self.y ) min_y = context.data_bbox.yrange()[0] coords.append( context.geom(self.x[-1], min_y) ) coords.append( context.geom(self.x[0], min_y) ) self.add( _PolygonObject(coords) ) class FillBetween( _FillComponent ): def __init__( self, x1, y1, x2, y2, **kw ): _FillComponent.__init__( self ) self.conf_setattr( "FillBetween" ) self.kw_init( kw ) self.x1, self.y1 = x1, y1 self.x2, self.y2 = x2, y2 def limits( self ): min_x = min( min(self.x1), min(self.x2) ) max_x = max( max(self.x1), max(self.x2) ) min_y = min( min(self.y1), min(self.y2) ) max_y = max( max(self.y1), max(self.y2) ) return BoundingBox( (min_x,min_y), (max_x,max_y) ) def make( self, context ): x = list(self.x1) + _tsil(self.x2) y = list(self.y1) + _tsil(self.y2) coords = map( context.geom, x, y ) self.add( _PolygonObject(coords) ) # ErrorBars ------------------------------------------------------------------- class _ErrorBar( _PlotComponent ): kw_rename = { 'color' : 'linecolor', 'width' : 'linewidth', 'type' : 'linetype', } def __init__( self ): _PlotComponent.__init__( self ) self.conf_setattr( "_ErrorBar" ) class ErrorBarsX( _ErrorBar ): def __init__( self, y, lo, hi, **kw ): _ErrorBar.__init__( self ) self.conf_setattr( "ErrorBarsX" ) self.kw_init( kw ) self.y = y self.lo = lo self.hi = hi def limits( self ): p = min( min(self.lo), min(self.hi) ), min(self.y) q = max( max(self.lo), max(self.hi) ), max(self.y) return BoundingBox( p, q ) def make( self, context ): l = _size_relative( self.barsize, context.dev_bbox ) for i in range(len(self.y)): p = context.geom( self.lo[i], self.y[i] ) q = context.geom( self.hi[i], self.y[i] ) l0 = _LineObject( p, q ) l1 = _LineObject( (p[0],p[1]-l), (p[0],p[1]+l) ) l2 = _LineObject( (q[0],q[1]-l), (q[0],q[1]+l) ) self.add( l0, l1, l2 ) class ErrorBarsY( _ErrorBar ): def __init__( self, x, lo, hi, **kw ): _ErrorBar.__init__( self ) self.conf_setattr( "ErrorBarsY" ) self.kw_init( kw ) self.x = x self.lo = lo self.hi = hi def limits( self ): p = min(self.x), min( min(self.lo), min(self.hi) ) q = max(self.x), max( max(self.lo), max(self.hi) ) return BoundingBox( p, q ) def make( self, context ): l = _size_relative( self.barsize, context.dev_bbox ) for i in range(len(self.x)): p = context.geom( self.x[i], self.lo[i] ) q = context.geom( self.x[i], self.hi[i] ) l0 = _LineObject( p, q ) l1 = _LineObject( (p[0]-l,p[1]), (p[0]+l,p[1]) ) l2 = _LineObject( (q[0]-l,q[1]), (q[0]+l,q[1]) ) self.add( l0, l1, l2 ) def SymmetricErrorBarsX( x, y, err, **kw ): import operator xlo = map( operator.sub, x, err ) xhi = map( operator.add, x, err ) return apply( ErrorBarsX, (y, xlo, xhi), kw ) def SymmetricErrorBarsY( x, y, err, **kw ): import operator ylo = map( operator.sub, y, err ) yhi = map( operator.add, y, err ) return apply( ErrorBarsY, (x, ylo, yhi), kw ) # Limits ---------------------------------------------------------------------- class _ErrorLimit( _PlotComponent ): kw_rename = { 'color' : 'linecolor', 'width' : 'linewidth', 'type' : 'linetype', } def __init__( self ): _PlotComponent.__init__( self ) self.conf_setattr( "_ErrorLimit" ) class UpperLimits( _ErrorLimit ): def __init__( self, x, ulimit, **kw ): _ErrorLimit.__init__( self ) self.conf_setattr( "UpperLimits" ) self.kw_init( kw ) self.x = x self.ulimit = ulimit def limits( self ): p = min(self.x), min(self.ulimit) q = max(self.x), max(self.ulimit) return BoundingBox( p, q ) def make( self, context ): l = _size_relative( self.size, context.dev_bbox ) for i in range(len(self.x)): p = context.geom( self.x[i], self.ulimit[i] ) l1 = _LineObject( (p[0]-l,p[1]), (p[0]+l,p[1]) ) l2 = _LineObject( (p[0],p[1]-2*l), (p[0],p[1]) ) l3 = _LineObject( (p[0],p[1]-2*l), (p[0]+l,p[1]-l) ) l4 = _LineObject( (p[0],p[1]-2*l), (p[0]-l,p[1]-l) ) self.add( l1, l2, l3, l4 ) class LowerLimits( _ErrorLimit ): def __init__( self, x, llimit, **kw ): _ErrorLimit.__init__( self ) self.conf_setattr( "UpperLimits" ) self.kw_init( kw ) self.x = x self.llimit = llimit def limits( self ): p = min(self.x), min(self.llimit) q = max(self.x), max(self.llimit) return BoundingBox( p, q ) def make( self, context ): l = _size_relative( self.size, context.dev_bbox ) for i in range(len(self.x)): p = context.geom( self.x[i], self.llimit[i] ) l1 = _LineObject( (p[0]-l,p[1]), (p[0]+l,p[1]) ) l2 = _LineObject( (p[0],p[1]+2*l), (p[0],p[1]) ) l3 = _LineObject( (p[0],p[1]+2*l), (p[0]+l,p[1]+l) ) l4 = _LineObject( (p[0],p[1]+2*l), (p[0]-l,p[1]+l) ) self.add( l1, l2, l3, l4 ) # Ellipses -------------------------------------------------------------------- class Ellipses( _PlotComponent ): kw_rename = { 'color' : 'linecolor', 'width' : 'linewidth', 'type' : 'linetype', } def __init__( self, x, y, rx, ry, angle=None, **kw ): _PlotComponent.__init__( self ) self.kw_init( kw ) self.x = x self.y = y self.rx = rx self.ry = ry self.angle = angle def limits( self ): # XXX:kludge minx, maxx = self.x[0], self.x[0] miny, maxy = self.y[0], self.y[0] for i in range(len(self.x)): r = max( self.rx[i], self.ry[i] ) minx = min( minx, self.x[i]-r ) miny = min( miny, self.y[i]-r ) maxx = max( maxx, self.x[i]+r ) maxy = max( maxy, self.y[i]+r ) return BoundingBox( (minx,miny), (maxx,maxy) ) def make( self, context ): for i in range(len(self.x)): p = context.geom( self.x[i], self.y[i] ) r = context.geom( \ self.x[i] + self.rx[i], \ self.y[i] + self.ry[i] ) rx, ry = pt_sub( r, p ) if self.angle is not None: e = _EllipseObject( p, rx, ry, self.angle[i] ) else: e = _EllipseObject( p, rx, ry ) self.add( e ) def Ellipse( x, y, rx, ry, angle=None, **kw ): if angle is None: args = ([x],[y],[rx],[ry]) else: args = ([x],[y],[rx],[ry],[angle]) return apply( Ellipses, args, kw ) def Circles( x, y, r, **kw ): return apply( Ellipses, (x,y,r,r), kw ) def Circle( x, y, r, **kw ): return apply( Circles, ([x],[y],[r]), kw ) # _PlotKey -------------------------------------------------------------------- class PlotKey( _PlotComponent ): kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', 'angle' : 'textangle', 'halign' : 'texthalign', 'valign' : 'textvalign', } def __init__( self, x, y, components, **kw ): _PlotComponent.__init__( self ) self.conf_setattr( "PlotKey" ) self.kw_init( kw ) self.x = x self.y = y self.components = components def make( self, context ): key_pos = context.plot_geom( self.x, self.y ) key_width = _size_relative( self.key_width, context.dev_bbox ) key_height = _size_relative( self.key_height, context.dev_bbox ) key_hsep = _size_relative( self.key_hsep, context.dev_bbox ) key_vsep = _size_relative( self.key_vsep, context.dev_bbox ) halign = self.kw_get( 'texthalign' ) if halign == 'left': text_pos = pt_add( (key_width/2+key_hsep,0), key_pos ) else: text_pos = pt_add( (-key_width/2-key_hsep,0), key_pos ) bbox = BoundingBox( (-key_width/2,-key_height/2), (key_width/2,key_height/2) ) bbox.shift( key_pos ) dp = 0, -(key_vsep + key_height) for comp in self.components: try: obj,str = comp except: obj = comp str = getattr( comp, "label", "" ) t = apply( _TextObject, (text_pos,str), self.kw_style ) self.add( t, obj.make_key(bbox) ) text_pos = pt_add( text_pos, dp ) bbox.shift( dp ) # XXX:deprecated def OldKey( x, y, labels, align='left', **kw ): kw['texthalign'] = align return apply( PlotKey, (x,y,labels), kw ) # _HalfAxis ------------------------------------------------------------------- def _magform( x ): "Given x, returns (a,b), where x = a*10^b [a >= 1., b integral]." if x == 0: return 0., 0 a, b = math.modf(math.log10(abs(x))) a, b = math.pow(10,a), int(b) if a < 1.: a, b = a * 10, b - 1 if x < 0.: a = -a return a, b def _format_ticklabel( x, range=0. ): if x == 0: return "0" a, b = _magform( x ) if abs(b) > 4: if a == 1.: return r"$10^{%d}$" % b elif a == -1.: return r"-$10^{%d}$" % b else: return r"$%g\times 10^{%d}$" % (a,b) if range < 1e-6: a, b = _magform( range ) return "%.*f" % (abs(b),x) return "%g" % x def _ticklist_linear( lo, hi, sep, origin=0. ): r = [] a = _ceil(float(lo - origin)/float(sep)) b = _floor(float(hi - origin)/float(sep)) #for i in range( a, b+1 ): # r.append( origin + i * sep ) r0 = origin + a*sep for i in range( b-a+1 ): r.append( r0 + i*sep ) return r def _pow10(x): return math.pow(10,x) def _log10(x): return math.log10(x) def _ticks_default_linear( lim ): a, b = _magform( (lim[1] - lim[0])/5. ) if a < (1 + 2)/2.: x = 1 elif a < (2 + 5)/2.: x = 2 elif a < (5 + 10)/2.: x = 5 else: x = 10 major_div = x * math.pow(10, b) return _ticklist_linear( lim[0], lim[1], major_div ) def _ticks_default_log( lim ): log_lim = _log10(lim[0]), _log10(lim[1]) nlo = _ceil( math.log10(lim[0]) ) nhi = _floor( math.log10(lim[1]) ) nn = nhi - nlo +1 if nn >= 10: return map( _pow10, _ticks_default_linear(log_lim) ) elif nn >= 2: return map( _pow10, range(nlo, nhi+1) ) else: return _ticks_default_linear( lim ) def _ticks_num_linear( lim, num ): ticks = [] a = lim[0] b = (lim[1] - lim[0])/float(num-1) for i in range(num): ticks.append( a + i*b ) return ticks def _ticks_num_log( lim, num ): ticks = [] a = math.log10(lim[0]) b = (math.log10(lim[1]) - a)/float(num - 1) for i in range(num): ticks.append( a + i*b ) return map( _pow10, ticks ) def _subticks_linear( lim, ticks, num=None ): major_div = (ticks[-1] - ticks[0])/float(len(ticks) - 1) if num is None: _num = 4 a, b = _magform( major_div ) if 1. < a < (2 + 5)/2.: _num = 3 else: _num = num minor_div = major_div/float(_num+1) return _ticklist_linear( lim[0], lim[1], minor_div, ticks[0] ) def _subticks_log( lim, ticks, num=None ): log_lim = _log10(lim[0]), _log10(lim[1]) nlo = _ceil( math.log10(lim[0]) ) nhi = _floor( math.log10(lim[1]) ) nn = nhi - nlo +1 if nn >= 10: return map( _pow10, _subticks_linear(log_lim, map(_log10,ticks), num) ) elif nn >= 2: minor_ticks = [] for i in range(nlo-1,nhi+1): for j in range(1,10): z = j * _pow10(i) if lim[0] <= z and z <= lim[1]: minor_ticks.append(z) return minor_ticks else: return _subticks_linear( lim, ticks, num ) class _Group: def __init__( self, objs ): self.objs = objs[:] def bbox( self, context ): bb = BoundingBox() for obj in self.objs: bb.union( obj.bbox(context) ) return bb class _HalfAxis( _PlotComponent ): func_ticks_default = _ticks_default_linear, _ticks_default_log func_ticks_num = _ticks_num_linear, _ticks_num_log func_subticks_default = _subticks_linear, _subticks_log func_subticks_num = _subticks_linear, _subticks_log _attr_map = { 'labeloffset' : 'label_offset', 'major_ticklabels' : 'ticklabels', 'major_ticks' : 'ticks', 'minor_ticks' : 'subticks', } def __init__( self, **kw ): _PlotComponent.__init__( self ) self.kw_init( kw ) self.conf_setattr( "_HalfAxis" ) def __getattr__( self, name ): return self.__dict__[ self._attr_map.get(name,name) ] def __setattr__( self, name, value ): self.__dict__[ self._attr_map.get(name,name) ] = value def _ticks( self, context ): log = self._log( context ) _range = self._range( context ) if self.ticks is None: return self.func_ticks_default[log]( _range ) elif type(self.ticks) == type(0): return self.func_ticks_num[log]( _range, self.ticks ) else: return self.ticks def _subticks( self, context, ticks ): log = self._log( context ) _range = self._range( context ) if self.subticks is None: return self.func_subticks_default[log]( _range, ticks ) elif type(self.subticks) == type(0): return self.func_subticks_num[log]( \ _range, ticks, self.subticks ) else: return self.subticks def _ticklabels( self, context, ticks ): if self.ticklabels is None: range = [ max(ticks) - min(ticks) ] * len(ticks) return map( _format_ticklabel, ticks, range ) else: return self.ticklabels def _make_ticklabels( self, context, pos, labels ): if labels is None or not len(labels) > 0: return dir = self.ticklabels_dir offset = _size_relative( self.ticklabels_offset, \ context.dev_bbox ) if self.draw_ticks and self.tickdir > 0: offset = offset + _size_relative( \ self.ticks_size, context.dev_bbox ) labelpos = [] for i in range(len(labels)): labelpos.append( \ self._pos(context, pos[i], dir*offset) ) halign, valign = self._align() style = { "halign" : halign, "valign" : valign } style.update( self.ticklabels_style ) l = apply( _LabelsObject, (labelpos, labels), style ) self.add( l ) def _make_spine( self, context ): a, b = self._range( context ) p = self._pos( context, a ) q = self._pos( context, b ) self.add( apply(_LineObject, (p, q), self.spine_style) ) def _make_ticks( self, context, ticks, size, style ): if ticks is None or not len(ticks) > 0: return dir = self.tickdir * self.ticklabels_dir ticklen = self._dpos( dir *\ _size_relative(size, context.dev_bbox) ) tickpos = [] for tick in ticks: tickpos.append( self._pos(context, tick) ) self.add( apply(_CombObject, (tickpos, ticklen), style) ) def make( self, context ): if self.draw_nothing: return ticks = self._ticks( context ) subticks = self._subticks( context, ticks ) ticklabels = self._ticklabels( context, ticks ) implicit_draw_subticks = self.draw_subticks is None and \ self.draw_ticks implicit_draw_ticklabels = self.draw_ticklabels is None and \ (self.range is not None or self.ticklabels is not None) if self.draw_grid: self._make_grid( context, ticks ) if self.draw_axis: if self.draw_subticks or implicit_draw_subticks: self._make_ticks( context, subticks, \ self.subticks_size, \ self.subticks_style ) if self.draw_ticks: self._make_ticks( context, ticks, \ self.ticks_size, self.ticks_style ) if self.draw_spine: self._make_spine( context ) if self.draw_ticklabels or implicit_draw_ticklabels: self._make_ticklabels( context, ticks, ticklabels ) ## has to be made last if self.label is not None: self.add( apply(_BoxLabel, (_Group(self.device_objects), self.label, self._side(), self.label_offset),\ self.label_style) ) class _HalfAxisX( _HalfAxis ): def _pos( self, context, a, db=0. ): p = context.geom( a, self._intercept(context) ) return p[0], p[1] + db def _dpos( self, d ): return 0., d def _align( self ): if self.ticklabels_dir < 0: return 'center', 'top' else: return 'center', 'bottom' def _intercept( self, context ): if self.intercept is not None: return self.intercept limits = context.data_bbox if self.ticklabels_dir < 0: return limits.yrange()[0] else: return limits.yrange()[1] def _log( self, context ): if self.log is None: return context.xlog return self.log def _side( self ): if self.ticklabels_dir < 0: return 'bottom' else: return 'top' def _range( self, context ): if self.range is not None: a,b = self.range if a is None or b is None: c,d = context.data_bbox.xrange() if a is None: a = c if b is None: b = d return a,b else: return self.range return context.data_bbox.xrange() def _make_grid( self, context, ticks ): if ticks is None: return for tick in ticks: self.add( apply(LineX, (tick,), self.grid_style) ) class _HalfAxisY( _HalfAxis ): def _pos( self, context, a, db=0. ): p = context.geom( self._intercept(context), a ) return p[0] + db, p[1] def _dpos( self, d ): return d, 0. def _align( self ): if self.ticklabels_dir > 0: return 'left', 'center' else: return 'right', 'center' def _intercept( self, context ): if self.intercept is not None: return self.intercept limits = context.data_bbox if self.ticklabels_dir > 0: return limits.xrange()[1] else: return limits.xrange()[0] def _log( self, context ): if self.log is None: return context.ylog return self.log def _side( self ): if self.ticklabels_dir > 0: return 'right' else: return 'left' def _range( self, context ): if self.range is not None: a,b = self.range if a is None or b is None: c,d = context.data_bbox.yrange() if a is None: a = c if b is None: b = d return a,b else: return self.range return context.data_bbox.yrange() def _make_grid( self, context, ticks ): if ticks is None: return for tick in ticks: self.add( apply(LineY, (tick,), self.grid_style) ) # _BoxLabel ------------------------------------------------------------------- class _BoxLabel( _PlotComponent ): kw_rename = { 'face' : 'fontface', 'size' : 'fontsize', } def __init__( self, obj, str, side, offset, **kw ): _PlotComponent.__init__( self ) self.kw_init( kw ) self.obj = obj self.str = str self.side = side self.offset = offset def make( self, context ): bb = self.obj.bbox( context ) offset = _size_relative( self.offset, context.dev_bbox ) if self.side == 'top': p = bb.upperleft() q = bb.upperright() elif self.side == 'bottom': p = bb.lowerleft() q = bb.lowerright() offset = -offset elif self.side == 'left': p = bb.lowerleft() q = bb.upperleft() elif self.side == 'right': p = bb.upperright() q = bb.lowerright() lt = apply( _LineTextObject, (p, q, self.str, offset), \ self.kw_style ) self.add( lt ) # _PlotComposite -------------------------------------------------------------- class _PlotComposite( _StyleKeywords ): def __init__( self, **kw ): self.kw_init( kw ) self.components = [] self.dont_clip = 0 def add( self, *args ): for obj in args: self.components.append( obj ) def clear( self ): self.components = [] def empty( self ): return len(self.components) == 0 def limits( self ): bb = BoundingBox() for obj in self.components: bb.union( obj.limits() ) return bb def make( self, context ): pass def bbox( self, context ): self.make( context ) bb = BoundingBox() for obj in self.components: bb.union( obj.bbox(context) ) return bb def render( self, context ): self.make( context ) self.kw_predraw( context ) if not self.dont_clip: context.do_clip() for obj in self.components: obj.render( context ) self.kw_postdraw( context ) # Frame ----------------------------------------------------------------------- class Frame( _PlotComposite ): def __init__( self, labelticks=(0,1,1,0), **kw ): apply( _PlotComposite.__init__, (self,), kw ) self.dont_clip = 1 self.x2 = _HalfAxisX() self.x2.draw_ticklabels = labelticks[0] self.x2.ticklabels_dir = 1 self.x1 = _HalfAxisX() self.x1.draw_ticklabels = labelticks[1] self.x1.ticklabels_dir = -1 self.y1 = _HalfAxisY() self.y1.draw_ticklabels = labelticks[2] self.y1.ticklabels_dir = -1 self.y2 = _HalfAxisY() self.y2.draw_ticklabels = labelticks[3] self.y2.ticklabels_dir = 1 def make( self, context ): self.clear() self.add( self.x1, self.x2, self.y1, self.y2 ) # _PlotContainer -------------------------------------------------------------- def _open_output( filename ): if filename == '-': import sys return sys.stdout else: # b is for windows return open( filename, 'wb' ) def _close_output( file ): if 2 < file.fileno(): file.close() else: file.flush() def _draw_text( device, p, str, **kw ): device.save_state() for key,val in kw.items(): device.set( key, val ) device.text( p, str ) device.restore_state() def win_temp_path(): """ Intended for Windows, returns a valid temp directory, or at least the current working directory. """ import os if os.environ.has_key('TEMP'): if os.path.exists(os.environ['TEMP']): return(os.environ['TEMP']) else: possible_temp_paths = [ '\\temp', '\\winnt\\temp', \ '\\windows\\temp', '\\tmp' ] for i in possible_temp_paths: if os.path.exists(i): return i return os.getcwd() class _PlotContainer( _ConfAttributes ): def __init__( self, **kw ): apply( self.conf_setattr, ("_PlotContainer",), kw ) def empty( self ): pass def interior( self, device, exterior ): TOL = 0.005 interior = exterior.copy() region_diagonal = exterior.diagonal() for i in range(10): bb = self.exterior( device, interior ) dll = pt_sub( exterior.lowerleft(), bb.lowerleft() ) dur = pt_sub( exterior.upperright(), bb.upperright() ) sll = pt_len(dll) / region_diagonal sur = pt_len(dur) / region_diagonal if sll < TOL and sur < TOL: # XXX:fixme if self.aspect_ratio is not None: interior.make_aspect_ratio(\ self.aspect_ratio ) return interior scale = interior.diagonal() / bb.diagonal() dll = pt_mul( scale, dll ) dur = pt_mul( scale, dur ) interior = BoundingBox( pt_add(interior.lowerleft(), dll), pt_add(interior.upperright(), dur) ) raise BigglesError def exterior( self, device, interior ): return interior.copy() def compose_interior( self, device, interior ): if self.title is not None: offset = _size_relative( self.title_offset, interior ) exterior = self.exterior( device, interior ) x = interior.center()[0] y = exterior.yrange()[1] + offset style = self.title_style.copy() style["fontsize"] = _fontsize_relative( \ self.title_style["fontsize"], interior, device ) style["texthalign"] = "center" style["textvalign"] = "bottom" apply( _draw_text, (device, (x,y), self.title), style ) def compose( self, device, region ): if self.empty(): raise BigglesError( "empty container" ) exterior = region.copy() if self.title is not None: offset = _size_relative( self.title_offset, exterior ) fontsize = _fontsize_relative( \ self.title_style["fontsize"], exterior, device ) exterior.deform( -offset-fontsize, 0, 0, 0 ) interior = self.interior( device, exterior ) self.compose_interior( device, interior ) def page_compose( self, device ): device.open() bb = BoundingBox( device.lowerleft, device.upperright ) device.bbox = bb.copy() for key,val in config.options('default').items(): device.set( key, val ) bb.expand( -self.page_margin ) self.compose( device, bb ) device.close() def show( self, width=None, height=None ): import os if width is None: width = config.value('screen','width') if height is None: height = config.value('screen','height') if os.name == 'posix': self.show_x11( width, height ) elif os.name == 'dos' or os.name == 'nt': self.show_win( width, height ) else: _message( "show: system type '%s' not supported" \ % os.name ) def show_x11( self, width, height ): persistent = config.interactive() and \ config.bool('screen','persistent') device = renderer.ScreenRenderer( persistent, width, height ) self.page_compose( device ) device.delete() def show_win( self, width, height ): """ Substitute for show() that will work on Windows. Generates temporary files somewhere that end with '_biggles.png'. These temporary files are not deleted, they must be manually cleaned up during normal temp directory maintenance. """ import os, tempfile #tf = os.path.join( win_temp_path(), 'biggles_graph.png' ) tf = tempfile.mktemp('_biggles.png') self.write_img( width, height, tf ) os.startfile( tf ) def psprint( self, printcmd=None, **kw ): import os, copy if os.name != 'posix': _message( "psprint: system type '%s' not supported" \ % os.name ) if printcmd is None: printcmd = config.value("printer","command") opt = copy.copy( config.options("postscript") ) opt.update( kw ) _message( 'printing plot with "%s"' % printcmd ) printer = os.popen( printcmd, 'w' ) device = apply( renderer.PSRenderer, (printer,), opt ) self.page_compose( device ) device.delete() printer.close() def write_eps( self, filename, **kw ): opt = copy.copy( config.options("postscript") ) opt.update( kw ) file = _open_output( filename ) device = apply( renderer.PSRenderer, (file,), opt ) self.page_compose( device ) device.delete() _close_output( file ) def write_img( self, *args ): if len(args) == 4: type,width,height,filename = args elif len(args) == 3: import string width,height,filename = args type = string.lower( filename[-3:] ) file = _open_output( filename ) device = renderer.ImageRenderer( type, width, height, file ) self.page_compose( device ) device.delete() _close_output( file ) save_as_eps = write_eps save_as_img = write_img def draw_piddle( self, canvastype=None, size=(500,500) ): from device.piddle import PiddleRenderer device = PiddleRenderer( canvastype, size ) self.page_compose( device ) canvas = device.canvas device.delete() return canvas def write_back_png( self, *args ): """ Saves PNG file in temporary file. Returns file contents. """ import tempfile, os if len(args) == 2: width,height = args type = 'png' file = tempfile.mktemp('_biggles.png') self.write_img(type, width, height, file) f = open(file, 'rb') output = f.read() f.close() os.remove(file) return output def multipage( plots, filename, **kw ): file = _open_output( filename ) opt = copy.copy( config.options("postscript") ) opt.update( kw ) device = apply( renderer.PSRenderer, (file,), opt ) for plot in plots: plot.page_compose( device ) device.delete() _close_output( file ) # ----------------------------------------------------------------------------- def _limits_axis( content_range, gutter, user_range, log ): r0, r1 = 0, 1 if content_range is not None: a, b = content_range if a is not None: r0 = a if b is not None: r1 = b if gutter is not None: dx = 0.5 * gutter * (r1 - r0) a = r0 - dx if not log or a > 0: r0 = a r1 = r1 + dx if user_range is not None: a, b = user_range if a is not None: r0 = a if b is not None: r1 = b if r0 == r1: r0 = r0 - 1 r1 = r1 + 1 return r0, r1 def _limits( content_bbox, gutter, xlog, ylog, xrange, yrange ): xr = _limits_axis( content_bbox.xrange(), gutter, xrange, xlog ) yr = _limits_axis( content_bbox.yrange(), gutter, yrange, ylog ) return BoundingBox( (xr[0],yr[0]), (xr[1],yr[1]) ) # Plot ------------------------------------------------------------------------ class Plot( _PlotContainer ): def __init__( self, **kw ): apply( _PlotContainer.__init__, (self,) ) apply( self.conf_setattr, ("Plot",), kw ) self.content = _PlotComposite() def __iadd__( self, other ): self.add( other ) def empty( self ): return self.content.empty() def add( self, *args ): apply( self.content.add, args ) def limits( self ): return _limits( self.content.limits(), self.gutter, \ self.xlog, self.ylog, self.xrange, self.yrange ) def compose_interior( self, device, region, limits=None ): if limits is None: limits = self.limits() context = _PlotContext( device, region, limits, xlog=self.xlog, ylog=self.ylog ) self.content.render( context ) def compose( self, device, region, limits=None ): interior = self.interior( device, region ) self.compose_interior( device, interior, limits ) # FramedPlot ------------------------------------------------------------------ class FramedPlot( _PlotContainer ): def __init__( self, **kw ): apply( _PlotContainer.__init__, (self,) ) self.content1 = _PlotComposite() self.content2 = _PlotComposite() self.x1 = _HalfAxisX() self.x1.ticklabels_dir = -1 self.y1 = _HalfAxisY() self.y1.ticklabels_dir = -1 self.x2 = _HalfAxisX() self.x2.draw_ticklabels = None self.y2 = _HalfAxisY() self.y2.draw_ticklabels = None self.frame = _Alias( self.x1, self.x2, self.y1, self.y2 ) self.frame1 = _Alias( self.x1, self.y1 ) self.frame2 = _Alias( self.x2, self.y2 ) self.x = _Alias( self.x1, self.x2 ) self.y = _Alias( self.y1, self.y2 ) apply( self.conf_setattr, ("FramedPlot",), kw ) _attr_map = { "xlabel" : ("x1", "label"), "ylabel" : ("y1", "label"), "xlog" : ("x1", "log"), "ylog" : ("y1", "log"), "xrange" : ("x1", "range"), "yrange" : ("y1", "range"), "xtitle" : ("x1", "label"), "ytitle" : ("y1", "label"), } def __repr__( self ): return "" def __getattr__( self, name ): if self._attr_map.has_key( name ): xs = self._attr_map[ name ] obj = self for x in xs[:-1]: obj = getattr( obj, x ) return getattr( obj, xs[-1] ) else: return self.__dict__[name] def __setattr__( self, name, value ): if self._attr_map.has_key( name ): xs = self._attr_map[ name ] obj = self for x in xs[:-1]: obj = getattr( obj, x ) setattr( obj, xs[-1], value ) else: self.__dict__[name] = value def empty( self ): return self.content1.empty() and self.content2.empty() def add( self, *args ): apply( self.content1.add, args ) def add2( self, *args ): apply( self.content2.add, args ) def _xy2log( self ): return _first_not_none(self.x2.log, self.x1.log), \ _first_not_none(self.y2.log, self.y1.log) def _limits1( self ): return _limits( self.content1.limits(), self.gutter, self.x1.log, self.y1.log, \ self.x1.range, self.y1.range ) def _context1( self, device, region ): return _PlotContext( device, region, self._limits1(), xlog=self.x1.log, ylog=self.y1.log ) def _limits2( self ): limits = self.content2.limits() if self.content2.empty(): limits = self.content1.limits() xlog, ylog = self._xy2log() xrange = _first_not_none( self.x2.range, self.x1.range ) yrange = _first_not_none( self.y2.range, self.y1.range ) return _limits( limits, self.gutter, xlog, ylog, \ xrange, yrange ) def _context2( self, device, region ): xlog, ylog = self._xy2log() return _PlotContext( device, region, self._limits2(), xlog, ylog ) def exterior( self, device, region ): bbox = BoundingBox() context1 = self._context1( device, region ) bbox.union( self.x1.bbox(context1) ) bbox.union( self.y1.bbox(context1) ) context2 = self._context2( device, region ) bbox.union( self.x2.bbox(context2) ) bbox.union( self.y2.bbox(context2) ) return bbox def compose_interior( self, device, region ): _PlotContainer.compose_interior( self, device, region ) context1 = self._context1( device, region ) context2 = self._context2( device, region ) self.content1.render( context1 ) self.content2.render( context2 ) self.y2.render( context2 ) self.x2.render( context2 ) self.y1.render( context1 ) self.x1.render( context1 ) class OldCustomFramedPlot( FramedPlot ): def __init__( self, **kw ): apply( FramedPlot.__init__, (self,), kw ) self.x = self.x1 self.y = self.y1 # Table ----------------------------------------------------------------------- class _Grid: def __init__( self, nrows, ncols, bbox, cellpadding=0, cellspacing=0 ): self.nrows = nrows self.ncols = ncols w, h = bbox.width(), bbox.height() cp = _size_relative( cellpadding, bbox ) cs = _size_relative( cellspacing, bbox ) self.origin = pt_add( bbox.lowerleft(), (cp,cp) ) self.step_x = (w + cs)/ncols self.step_y = (h + cs)/nrows self.cell_dimen = self.step_x - cs - 2*cp, \ self.step_y - cs - 2*cp def cell( self, i, j ): ii = self.nrows-1 - i p = pt_add( self.origin, (j*self.step_x,ii*self.step_y) ) q = pt_add( p, self.cell_dimen ) return BoundingBox( p, q ) class Table( _PlotContainer ): def __init__( self, rows, cols, **kw ): apply( _PlotContainer.__init__, (self,) ) apply( self.conf_setattr, ("Table",), kw ) self.rows = rows self.cols = cols self.content = {} def __getitem__( self, key ): return self.content[key] def __setitem__( self, key, value ): self.content[key] = value def set( self, i, j, obj ): self.content[i,j] = obj def get( self, i, j ): return self.content.get( (i,j), None ) def exterior( self, device, interior ): ext = interior.copy() if self.align_interiors: g = _Grid( self.rows, self.cols, interior, \ self.cellpadding, self.cellspacing ) for key,obj in self.content.items(): subregion = apply( g.cell, key ) ext.union( obj.exterior(device, subregion) ) return ext def compose_interior( self, device, interior ): _PlotContainer.compose_interior( self, device, interior ) g = _Grid( self.rows, self.cols, interior, \ self.cellpadding, self.cellspacing ) for key,obj in self.content.items(): subregion = apply( g.cell, key ) if self.align_interiors: obj.compose_interior( device, subregion ) else: obj.compose( device, subregion ) # FramedArray ----------------------------------------------------------------- # # Hideous, but it works... # def _frame_draw( obj, device, region, limits, labelticks=(0,1,1,0) ): frame = Frame( labelticks=labelticks ) context = _PlotContext( device, region, limits, xlog=obj.xlog, ylog=obj.ylog ) frame.render( context ) def _frame_bbox( obj, device, region, limits, labelticks=(0,1,1,0) ): frame = Frame( labelticks=labelticks ) context = _PlotContext( device, region, limits, xlog=obj.xlog, ylog=obj.ylog ) return frame.bbox( context ) def _range_union( a, b ): if a is None: return b if b is None: return a return min(a[0],b[0]), max(a[1],b[1]) class FramedArray( _PlotContainer ): def __init__( self, nrows, ncols, **kw ): apply( _PlotContainer.__init__, (self,) ) self.nrows = nrows self.ncols = ncols self.content = {} for i in range(nrows): for j in range(ncols): self.content[i,j] = Plot() apply( self.conf_setattr, ("FramedArray",), kw ) _attr_distribute = [ 'gutter', 'xlog', 'ylog', 'xrange', 'yrange', ] _attr_deprecated = { 'labeloffset' : 'label_offset', 'labelsize' : 'label_size', } def __setattr__( self, name, value ): if name in self._attr_distribute: for obj in self.content.values(): setattr( obj, name, value ) else: _name = self._attr_deprecated.get( name, name ) self.__dict__[_name] = value def __getitem__( self, key ): return self.content[key] def _limits( self, i, j ): if self.uniform_limits: return self._limits_uniform() else: return self._limits_nonuniform( i, j ) def _limits_uniform( self ): limits = BoundingBox() for obj in self.content.values(): limits.union( obj.limits() ) return limits def _limits_nonuniform( self, i, j ): lx = None for k in range(self.nrows): l = self.content[k,j].limits() lx = _range_union( l.xrange(), lx ) ly = None for k in range(self.ncols): l = self.content[i,k].limits() ly = _range_union( l.yrange(), ly ) return BoundingBox( (lx[0],ly[0]), (lx[1],ly[1]) ) def _grid( self, interior ): return _Grid( self.nrows, self.ncols, interior, cellspacing=self.cellspacing ) def _frames_bbox( self, device, interior ): bb = BoundingBox() g = self._grid( interior ) corners = [(0,0),(self.nrows-1,self.ncols-1)] for key in corners: obj = self.content[key] subregion = apply( g.cell, key ) limits = apply( self._limits, key ) axislabels = [0,0,0,0] if key[0] == self.nrows-1: axislabels[1] = 1 if key[1] == 0: axislabels[2] = 1 bb.union( _frame_bbox(obj, device, subregion, \ limits, axislabels) ) return bb def exterior( self, device, interior ): bb = self._frames_bbox( device, interior ) labeloffset = _size_relative( self.label_offset, interior ) labelsize = _fontsize_relative( \ self.label_size, interior, device ) margin = labeloffset + labelsize if self.xlabel is not None: bb.deform( 0, margin, 0, 0 ) if self.ylabel is not None: bb.deform( 0, 0, margin, 0 ) return bb def _frames_draw( self, device, interior ): g = self._grid( interior ) for key,obj in self.content.items(): subregion = apply( g.cell, key ) limits = apply( self._limits, key ) axislabels = [0,0,0,0] if key[0] == self.nrows-1: axislabels[1] = 1 if key[1] == 0: axislabels[2] = 1 _frame_draw( obj, device, subregion, \ limits, axislabels ) def _data_draw( self, device, interior ): g = self._grid( interior ) for key,obj in self.content.items(): subregion = apply( g.cell, key ) limits = apply( self._limits, key ) obj.compose_interior( device, subregion, limits ) def _labels_draw( self, device, interior ): bb = self._frames_bbox( device, interior ) labeloffset = _size_relative( self.label_offset, interior ) labelsize = _fontsize_relative( \ self.label_size, interior, device ) device.save_state() device.set( 'fontsize', labelsize ) device.set( 'texthalign', 'center' ) if self.xlabel is not None: x = interior.center()[0] y = bb.yrange()[0] - labeloffset device.set( 'textvalign', 'top' ) device.text( (x,y), self.xlabel ) if self.ylabel is not None: x = bb.xrange()[0] - labeloffset y = interior.center()[1] device.set( 'textangle', 90. ) device.set( 'textvalign', 'bottom' ) device.text( (x,y), self.ylabel ) device.restore_state() def add( self, *args ): for obj in self.content.values(): apply( obj.add, args ) def compose_interior( self, device, interior ): _PlotContainer.compose_interior( self, device, interior ) self._data_draw( device, interior ) self._frames_draw( device, interior ) self._labels_draw( device, interior ) # Text ------------------------------------------------------------------------ class Text( _PlotContainer ): def __init__( self, text, **kw ): apply( _PlotContainer.__init__, (self,) ) apply( self.conf_setattr, ("Text",), kw ) import string self.lines = string.split( text, "\n" ) if self.lines[0] == '': del self.lines[0] if self.lines[-1] == '': del self.lines[-1] def compose( self, device, region ): device.save_state() context = _PlotContext( device, region, region ) fontsize = _fontsize_relative( self.fontsize, context.dev_bbox, device ) device.set( 'fontsize', fontsize ) block_w = 0 for line in self.lines: block_w = max( block_w, device.textwidth(line) ) dy = fontsize * self.lineheight block_h = fontsize + dy * (len(self.lines)-1) x0, y0 = region.center() y0 = y0 + block_h/2. if self.halign == 'left': x0 = x0 - (region.width() - block_w)/2. elif self.halign == 'right': x0 = x0 + (region.width() - block_w)/2. if self.valign == 'top': y0 = y0 + (region.height() - block_h)/2. elif self.valign == 'bottom': y0 = y0 - (region.height() - block_h)/2. if self.justify == 'left': x0 = x0 - block_w/2 elif self.justify == 'right': x0 = x0 + block_w/2 ## render block = _PlotComposite() y = y0 for line in self.lines: block.add( DataLabel(x0, y, line, \ halign=self.justify, valign='top', \ fontface=self.fontface, \ fontsize=self.fontsize) ) y = y - dy block.render( context ) device.restore_state() # Inset ----------------------------------------------------------------------- class _Inset: def __init__( self, p, q, plot ): self.plot_limits = BoundingBox( p, q ) self.plot = plot def render( self, context ): region = self.bbox( context ) self.plot.compose_interior( context.draw, region ) class DataInset( _Inset ): def bbox( self, context ): p = apply( context.geom, self.plot_limits.lowerleft() ) q = apply( context.geom, self.plot_limits.upperright() ) return BoundingBox( p, q ) def limits( self ): return self.plot_limits.copy() class PlotInset( _Inset ): def bbox( self, context ): p = apply( context.plot_geom, self.plot_limits.lowerleft() ) q = apply( context.plot_geom, self.plot_limits.upperright() ) return BoundingBox( p, q ) def limits( self ): return BoundingBox() python2-biggles-1.6.6/src/Makefile.win0000644000175100017510000000325307554425070016615 0ustar noltanolta# Makefile for the Biggles plot library on Microsoft Visual C/C++ 6 # # Targets: # TARGET: build the target _biggles.pyd only # ALL (default): build _biggles.pyd and libplot.pyd # CLEAN: delete all generated files (for _biggles.pyd only) # REBUILD: CLEAN + TARGET # CLEANALL: delete all generated files for _biggles.pyd and libplot.pyd # REBUILDALL: CLEANALL + ALL # LISTDLL: list the contents of the dll (pyd) PROJ = _biggles TARGET = $(PROJ).pyd # Locations of required files # Python header location PYTHONDIR = $(PYTHONHOME) # Check that the given file locations exist !if !exist($(PYTHONDIR)) ! ERROR PYTHONDIR ($(PYTHONDIR)) doesn't exist. Aborting. !endif INCLUDE = $(PYTHONDIR)\include;$(INCLUDE) # Define the targets ALL: $(TARGET) MAKELIBPLOTALL TARGET: $(TARGET) CPP = cl.exe CPPFLAGS = /nologo /MD /W3 /GX /O2 /DWIN32 /DNDEBUG /D_WINDOWS /D_USRDLL LINK_CMD = link LINK_FLAGS = /nologo /dll /incremental:no /machine:I386 /LIBPATH:$(PYTHONDIR)\libs $(PROJ).obj: $(PROJ).c $(CPP) /c $(CPPFLAGS) $** $(TARGET): $(PROJ).obj $(LINK_CMD) $(LINK_FLAGS) /export:init$(PROJ) $** /out:$@ MAKELIBPLOTALL: @cd libplot $(MAKE) /$(MAKEFLAGS) /nologo /f Makefile.ms ALL @cd .. CLEAN: if exist $(PROJ).obj del $(PROJ).obj if exist $(PROJ).lib del $(PROJ).lib if exist $(PROJ).exp del $(PROJ).exp if exist $(TARGET) del $(TARGET) REBUILD: CLEAN TARGET CLEANALL: CLEAN @cd libplot $(MAKE) /$(MAKEFLAGS) /nologo /f Makefile.ms CLEAN @cd .. REBUILDALL: CLEANALL ALL LISTDLL: @dumpbin /EXPORTS $(TARGET) # end of file python2-biggles-1.6.6/src/confit.pyc0000644000175100017510000000556611357716146016374 0ustar noltanolta :c@sHddkZddklZlZlZdZdddYZdS(iN(tatoitsplittstripc Cst|}|djodSnyt|dSWn7tj o+yt|SWqltj oqlXnX|ddjo|ddjoh}ttt|dd!d}xS|D]K}|djoqnt|d \}}tt||t|s  python2-biggles-1.6.6/src/func.py0000644000175100017510000000521210611710022015641 0ustar noltanolta# # $Id: func.py,v 1.21 2007/04/19 15:51:46 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import biggles, config import string def plot( a, b=None, **kw ): if b is None: x = range(1,len(a)+1) y = a else: x = a y = b p = apply( biggles.FramedPlot, (), kw ) p.add( biggles.Curve(x, y) ) p.show() def read_column( num, filename, atox=float, \ comment_char=None, return_numpy=None ): import string if comment_char is None: comment_char = config.value('read_column','comment_char') if return_numpy is None: return_numpy = config.value('read_column','return_numpy') x = [] f = open( filename ) lines = map( string.strip, f.readlines() ) f.close() lines = filter( None, lines ) # get rid of '' for line in lines: if line[0] == comment_char[0]: continue column = string.split( line ) x.append( column[num] ) x = map( atox, x ) if return_numpy: import numpy return numpy.array( x ) return x def read_rows( filename, atox=float, comment_char=None, return_numpy=None ): import string if comment_char is None: comment_char = config.value('read_rows','comment_char') if return_numpy is None: return_numpy = config.value('read_rows','return_numpy') if return_numpy: import numpy x = [] f = open( filename ) lines = map( string.strip, f.readlines() ) f.close() lines = filter( None, lines ) # get rid of blank lines for line in lines: if line[0] == comment_char[0]: continue row = map( atox, string.split(line) ) if return_numpy: row = numpy.array( row ) x.append( row ) return x def read_matrix( filename, atox=float, comment_char=None, return_numpy=None ): if comment_char is None: comment_char = config.value('read_matrix','comment_char') if return_numpy is None: return_numpy = config.value('read_matrix','return_numpy') m = read_rows( filename, atox=atox, comment_char=comment_char, \ return_numpy=0 ) if return_numpy: import numpy return numpy.array( m ) return m python2-biggles-1.6.6/src/config.ini0000644000175100017510000001006311113636574016323 0ustar noltanolta# # $Id: config.ini,v 1.94 2008/11/28 00:38:20 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # -------------------------------------------------- # biggles checks here if it fails to find an option # in other sections # [default] fillcolor = 0xf0f0f0 filltype = 0x0 fontface = HersheySans fontsize = 3.0 fontsize_min = 1.25 symboltype = diamond symbolsize = 2.0 textangle = 0.0 texthalign = center textvalign = center # lines beginning with this character will be # ignored by the read_* routines comment_char = # # if 1 the read_* routines will return numpy arrays return_numpy = 1 # -------------------------------------------------- [screen] # dimensions of window (pixels) # width = 512 height = 512 # make window persistent when using interactively? # persistent = yes # -------------------------------------------------- [printer] # command which postscript will be piped to # command = lpr # -------------------------------------------------- [postscript] # paper size name; accepts ISO sizes ("a0",..,"a4"), # ANSI sizes ("a",..,"e"), "letter", "ledger", "tabloid", # and "b5". # paper = letter # size of output region on the page # valid units are in,pt,cm,mm # width = 7.5in height = 7.5in # -------------------------------------------------- # default object parameters # [Contours] func_color = None func_linetype = None func_linewidth = None levels = 10 [FramedArray] cellspacing = 0.0 gutter = 0.1 label_offset = 0.9 label_size = 2.7 uniform_limits = 0 xlabel = None ylabel = None [FramedPlot] frame.grid_style = {linetype:dot} frame.tickdir = -1 frame1.draw_grid = 0 gutter = 0.1 xlog = 0 ylog = 0 [Geodesic] divisions = 100 [HammerAitoffPlot] aspect_ratio = 0.5 ribs_b = 2 ribs_l = 3 ribs_style = {linetype:dot,linewidth:0.5} [Histogram] drop_to_zero = 1 [Plot] gutter = 0.0 xlog = 0 xrange = None ylog = 0 yrange = None [PlotKey] key_height = 2.0 key_hsep = 2.0 key_vsep = 2.0 key_width = 4.0 kw_defaults = { fontsize : 2.5, texthalign : left } [Table] align_interiors = 0 cellpadding = 0.0 cellspacing = 2.0 # -------------------------------------------------- # internal; can change/disappear at any time # [_FillComponent] filltype = 0x1 [Text] fontface = HersheySerif fontsize = 3.0 justify = left halign = center lineheight = 1.2 valign = center [_HalfAxis] draw_axis = 1 draw_grid = 0 draw_nothing = 0 draw_spine = 1 draw_subticks = None draw_ticks = 1 draw_ticklabels = 1 grid_style = {linetype:dot} intercept = None label = None label_offset = 1.0 label_style = {fontsize:3.0} log = None range = None spine_style = {} subticks = None subticks_size = 0.75 subticks_style = {} tickdir = -1 ticks = None ticks_size = 1.5 ticks_style = {} ticklabels = None ticklabels_dir = 1 ticklabels_offset = 1.5 ticklabels_style = {fontsize:3.0} [_ErrorBar] barsize = 0.5 [_ErrorLimit] size = 0.6 [_LabelComponent] kw_defaults = { fontsize : 3.0, textangle : 0.0, texthalign : center, textvalign : center } [_LabelsComponent] kw_defaults = { fontsize : 2.5, textangle : 0.0, texthalign : center, textvalign : center } [_LineComponent] kw_defaults = {linewidth:1.0} [_PlotContainer] aspect_ratio = None page_margin = 0.1 title = None title_offset = 1.0 title_style = {fontsize:3.0} python2-biggles-1.6.6/src/geometry.pyc0000644000175100017510000002201111357716146016725 0ustar noltanolta 'Fc@sddkZddkZdZdZdZdZdZdZdZd Z d Z d dd YZ d Z dddYZ de fdYZdS(iNcCs"|d|d|d|dfS(Nii((tutv((s../src/geometry.pytpt_addscCs"|d|d|d|dfS(Nii((RR((s../src/geometry.pytpt_subscCs||d||dfS(Nii((taR((s../src/geometry.pytpt_mul scCsQti|ti|}}||d||d||d||dfS(Nii(tmathtcostsin(Rtangletcts((s../src/geometry.pytpt_rot#scCsti|d|dS(Nii(Rthypot(R((s../src/geometry.pytpt_len'scCsti|d|dS(Nii(Rtatan2(R((s../src/geometry.pytpt_angle*scCs&t|}|d||d|fS(Nii(R(Rtr((s../src/geometry.pytpt_unit-s cCsV|djo|Sn|djo|Snt|d|dt|d|dfS(Nii(tNonetmin(Rtb((s../src/geometry.pytpt_min1s   cCs|djo|Sn|djo|Snt|d|d}|djot|d|d}nt|d|d}|djot|d|d}n||fS(Nii(RtmaxR(RRtxty((s../src/geometry.pytpt_max6s    t BoundingBoxcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZRS(cGsQt|djo(tt||_tt||_nd|_d|_dS(Ni(tlentreduceRtp0Rtp1R(tselftargs((s../src/geometry.pyt__init__Es  cCs dt|it|ifS(Ns(%s,%s)(tstrRR(R ((s../src/geometry.pyt__str__MscCst|i|iS(N(RRR(R ((s../src/geometry.pytcopyPscCs|idjp |idjS(N(RRR(R ((s../src/geometry.pytis_nullSscCs5|iodSnt|id|idSdS(Ni(R&RtabsRR(R ((s../src/geometry.pytwidthVs cCs5|iodSnt|id|idSdS(Ni(R&RR'RR(R ((s../src/geometry.pytheight\s cCs5|iodSnti|i|iSdS(N(R&RRR R(R)(R ((s../src/geometry.pytdiagonalbs cCs-|iodSn|i|iSdS(N(R&RR)R((R ((s../src/geometry.pyt aspect_ratiohs cCs1|iodSn|id|idfSdS(Ni(R&RRR(R ((s../src/geometry.pytxrangens cCs1|iodSn|id|idfSdS(Ni(R&RRR(R ((s../src/geometry.pytyrangets cCs |iodSn|iSdS(N(R&RR(R ((s../src/geometry.pyt lowerleftzs cCs1|iodSn|id|idfSdS(Nii(R&RRR(R ((s../src/geometry.pyt upperlefts cCs |iodSn|iSdS(N(R&RR(R ((s../src/geometry.pyt upperrights cCs1|iodSn|id|idfSdS(Nii(R&RRR(R ((s../src/geometry.pyt lowerrights cCsB|i}|i}|d|dd|d|ddfS(Niig@(R,R-(R RR((s../src/geometry.pytcenters  cCs4t|i|i|_t|i|i|_dS(N(RRRR(R tother((s../src/geometry.pytunionscCs:t|i||f|_t|i||f|_dS(N(RRRR(R tdttdbtdltdr((s../src/geometry.pytdeformscCs.t|i||_t|i||_dS(N(RRR(R tdp((s../src/geometry.pytshiftscCsSt|d|i|if}t|i||_t|i||_dS(Ng@(RR(R)RRRR(R tfactorR:((s../src/geometry.pytexpands%cCsttt|i|||}ttt|i|||}ttt|i|||}ttt|i|||}t|t|t|||_t |t |t |||_ dS(N( RR RR.R1R/R0RRRR(R R tpRRR td((s../src/geometry.pytrotates ''''$cCs||ijoh|i||i}|id|id|df|_|id|id|df|_ne|i|i|}|id|d|idf|_|id|d|idf|_dS(Niii(R+R)R(RR(R tratiotdhtdw((s../src/geometry.pytmake_aspect_ratios%)%cCsp|id|djoP|d|idjo8|id|djo |d|idjodSndSdS(Nii(RR(R tq((s../src/geometry.pytcontainss (t__name__t __module__R"R$R%R&R(R)R*R+R,R-R.R/R0R1R2R4R9R;R=R@RDRF(((s../src/geometry.pyRCs,                     cCs|dd|dd|dd|dd}|dd|dd|dd|dd}|dd|dd|dd|dd}|dd|dd|dd|dd}||f||ffS(Nii((tAtBtC00tC01tC10tC11((s../src/geometry.pyt_matrix_multipys 2222tAffineTransformcBs,eZdZdZdZdZRS(cCsd|_ddf|_dS(Ngg?(gg(g?g(gg?(tttm(R ((s../src/geometry.pyR"s cCsp|id|idd||idd|}|id|idd||idd|}||fS(Nii(RQRR(R RRR>RE((s../src/geometry.pyt__call__s33cCsti|}ti|}|id|idd||idd|}|id|idd||idd|}||fS(Nii(tnumpytasarrayRQRR(R RRtx_ty_R>RE((s../src/geometry.pytcall_vecs 33cCs<||id|id|_t|i|i|_dS(Nii(RQt_matrix_multiplyRR(R R3((s../src/geometry.pytcomposes (RGRHR"RSRXRZ(((s../src/geometry.pyRPs   tRectilinearMapcBseZdZRS(c Csti||i|i}|i|i}|i|i}}|d||d}|d||d}||f|_|dfd|ff|_dS(Niig(RPR"R(R)R.RQRR( R tsrctdesttsxtsyR>REttxtty((s../src/geometry.pyR"s (RGRHR"(((s../src/geometry.pyR[s(((RRTRRRR RRRRRRRORPR[(((s../src/geometry.pyss          python2-biggles-1.6.6/src/config.py0000644000175100017510000000443507647375166016220 0ustar noltanolta# # $Id: config.py,v 1.34 2003/04/17 00:51:02 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import os, sys import confit _config = confit.Confit() # XXX:deprecated 1.4 _config.deprecated( ('screen','guess_interactive'), ('screen','persistent') ) # XXX:deprecated 1.5 _config.deprecated( \ ('HammerAitoffPlot','num_b_ribs'), ('HammerAitoffPlot','ribs_b') ) _config.deprecated( \ ('HammerAitoffPlot','num_l_ribs'), ('HammerAitoffPlot','ribs_l') ) _config.deprecated( \ ("readcolumn","use_numeric"), ("read_column","return_numpy") ) _config.deprecated( \ ("readcolumn","comment_char"), ("read_column","comment_char") ) # XXX:deprecated 1.6.4 _config.deprecated( ('printer','paper'), ('postscript','paper') ) #SITECONFIGFILE = os.path.join( imp.find_module("biggles")[1], "config.ini" ) SITECONFIGFILE = os.path.join( os.path.dirname(__file__), "config.ini" ) _config.read( SITECONFIGFILE ) if os.environ.has_key( "HOME" ): USERCONFIGFILE = os.path.join( os.environ["HOME"], ".biggles" ) _config.read( USERCONFIGFILE ) def interactive(): return hasattr( sys, "ps1" ) def bool( section, option ): global _config try: x = _config.get( section, option, "no" ) if x[0] == 'y': return 1 except: return 0 def value( section, option, notfound=None ): global _config return _config.get( section, option, notfound ) def options( section ): global _config return _config.get_section( section ) def configure( *args ): global _config if len(args) == 2: _config.set( "default", args[0], args[1] ) elif len(args) == 3: _config.set( args[0], args[1], args[2] ) python2-biggles-1.6.6/src/libplot/0000755000175100017510000000000011357716714016027 5ustar noltanoltapython2-biggles-1.6.6/src/libplot/__init__.py0000644000175100017510000000000007366153263020125 0ustar noltanoltapython2-biggles-1.6.6/src/libplot/Makefile0000644000175100017510000000177210611710022017450 0ustar noltanolta# # $Id: Makefile,v 1.3 2007/04/19 15:51:46 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # include ../../make.inc CPPFLAGS = $(BASE_CPPFLAGS) $(NUMPY_CPPFLAGS) $(LIBPLOT_CPPFLAGS) LDFLAGS = $(BASE_LDFLAGS) $(LIBPLOT_LDFLAGS) TARGETS = libplot.so include ../../make.rules python2-biggles-1.6.6/src/libplot/libplot.c0000644000175100017510000005466611357712020017643 0ustar noltanolta/* * $Id: libplot.c,v 1.12 2010/04/09 20:54:17 mrnolta Exp $ * * Copyright (C) 2001 Mike Nolta * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #include #include #include #include typedef int bool_t; #define TRUE 1 #define FALSE 0 #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #define PyArray_1D(v,i)\ (*((double *)((v)->data+(i)*(v)->strides[0]))) #define PyArray_2D(m,i,j)\ (*((double *)((m)->data+(i)*(m)->strides[0]+(j)*(m)->strides[1]))) #define PyArray_3D(m,i,j,k)\ (*((double *) ( (m)->data + \ (i)*(m)->strides[0] + \ (j)*(m)->strides[1] + \ (k)*(m)->strides[2])) ) #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b)) /***************************************************************************** * clipping code */ #define TOP 0x1 #define BOTTOM 0x2 #define RIGHT 0x4 #define LEFT 0x8 static unsigned char outcode( double x, double y, double xmin, double xmax, double ymin, double ymax ) { unsigned char code = 0x0; if ( x < xmin ) code |= LEFT; if ( x > xmax ) code |= RIGHT; if ( y < ymin ) code |= BOTTOM; if ( y > ymax ) code |= TOP; /* printf( "%d (%g,%g,%g) (%g,%g,%g)\n", code, xmin, x, xmax, ymin, y, ymax ); */ return code; } static bool_t cohen_sutherland( double xmin, double xmax, double ymin, double ymax, double x0, double y0, double x1, double y1, double *xc0, double *yc0, double *xc1, double *yc1 ) { unsigned out, out0, out1; bool_t accept, done; double x = 0., y = 0.; out0 = outcode( x0, y0, xmin, xmax, ymin, ymax ); out1 = outcode( x1, y1, xmin, xmax, ymin, ymax ); accept = FALSE; done = FALSE; do { if ( (out0 == 0) && (out1 == 0) ) { /* trivially inside */ accept = TRUE; done = TRUE; } else if ( (out0 & out1) != 0 ) { /* trivially outside */ done = TRUE; } else { out = ( out0 != 0 ) ? out0 : out1 ; if ( (out & TOP) != 0 ) { x = x0 + (x1 - x0)*(ymax - y0)/(y1 - y0); y = ymax; } else if ( (out & BOTTOM) != 0 ) { x = x0 + (x1 - x0)*(ymin - y0)/(y1 - y0); y = ymin; } else if ( (out & RIGHT) != 0 ) { y = y0 + (y1 - y0)*(xmax - x0)/(x1 - x0); x = xmax; } else if ( (out & LEFT) != 0 ) { y = y0 + (y1 - y0)*(xmin - x0)/(x1 - x0); x = xmin; } if ( out == out0 ) { x0 = x; y0 = y; out0 = outcode( x, y, xmin, xmax, ymin, ymax ); } else { x1 = x; y1 = y; out1 = outcode( x, y, xmin, xmax, ymin, ymax ); } } } while ( done != TRUE ); if ( accept == TRUE ) { *xc0 = x0; *yc0 = y0; *xc1 = x1; *yc1 = y1; /* printf( "(%g %g) (%g %g)\n", x0, y0, x1, y1 ); */ } return accept; } static void clipped_pl_fline_r( plPlotter *pl, double xmin, double xmax, double ymin, double ymax, double x0, double y0, double x1, double y1 ) { double xc0, yc0, xc1, yc1; bool_t accept; accept = cohen_sutherland( xmin, xmax, ymin, ymax, x0, y0, x1, y1, &xc0, &yc0, &xc1, &yc1 ); if ( accept == TRUE ) pl_fline_r( pl, xc0, yc0, xc1, yc1 ); } /****************************************************************************** * */ static PyObject * new( PyObject *self, PyObject *args ) { PyObject *o, *odict, *ofile, *key, *value; Py_ssize_t pos; char *type, *skey, *svalue; FILE *outfile; plPlotterParams *params; plPlotter *pl; if ( !PyArg_ParseTuple( args, "sOO", &type, &odict, &ofile ) ) return NULL; params = pl_newplparams(); if ( PyDict_Check(odict) ) { pos = 0; while ( PyDict_Next( odict, &pos, &key, &value ) ) { skey = PyString_AsString( key ); svalue = PyString_AsString( value ); pl_setplparam( params, skey, svalue ); } } else if ( odict != Py_None ) { PyErr_SetString( PyExc_TypeError, "not a dict" ); return NULL; } outfile = NULL; if ( PyFile_Check(ofile) ) { outfile = PyFile_AsFile( ofile ); } else if ( ofile != Py_None ) { PyErr_SetString( PyExc_TypeError, "not a file" ); return NULL; } pl = pl_newpl_r( type, NULL, outfile, NULL, params ); pl_deleteplparams( params ); o = PyCObject_FromVoidPtr( (void *) pl, NULL ); return Py_BuildValue( "O", o ); } /****************************************************************************** */ #define BGL_PL_FUNC(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "O", &o ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr );\ Py_INCREF( Py_None );\ return Py_None;\ } BGL_PL_FUNC( clear, pl_erase_r ) BGL_PL_FUNC( end_page, pl_closepl_r ) BGL_PL_FUNC( delete, pl_deletepl_r ) BGL_PL_FUNC( flush, pl_flushpl_r ) BGL_PL_FUNC( gsave, pl_savestate_r ) BGL_PL_FUNC( grestore, pl_restorestate_r ) BGL_PL_FUNC( begin_page, pl_openpl_r ) /****************************************************************************** */ #define BGL_PL_FUNC_I(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ int i0;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Oi", &o, &i0 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, i0 );\ Py_INCREF( Py_None );\ return Py_None;\ } BGL_PL_FUNC_I( set_fill_level, pl_filltype_r ) /****************************************************************************** */ #define BGL_PL_FUNC_D(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Od", &o, &d0 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0 );\ Py_INCREF( Py_None );\ return Py_None;\ } #define BGL_PL_FUNC_DD(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Odd", &o, &d0, &d1 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0, d1 );\ Py_INCREF( Py_None );\ return Py_None;\ } #define BGL_PL_FUNC_DDD(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1, d2;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Oddd", &o, &d0, &d1, &d2 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0, d1, d2 );\ Py_INCREF( Py_None );\ return Py_None;\ } #define BGL_PL_FUNC_DDDD(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1, d2, d3;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Odddd", &o, &d0, &d1, &d2, &d3 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0, d1, d2, d3 );\ Py_INCREF( Py_None );\ return Py_None;\ } #define BGL_PL_FUNC_DDDDD(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1, d2, d3, d4;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Oddddd", &o, &d0, &d1, &d2, &d3, &d4 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0, d1, d2, d3, d4 );\ Py_INCREF( Py_None );\ return Py_None;\ } #define BGL_PL_FUNC_DDDDDD(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1, d2, d3, d4, d5;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Odddddd",\ &o, &d0, &d1, &d2, &d3, &d4, &d5 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0, d1, d2, d3, d4, d5 );\ Py_INCREF( Py_None );\ return Py_None;\ } #define BGL_PL_FUNC_DDDDDDDD(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1, d2, d3, d4, d5, d6, d7;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Odddddddd",\ &o, &d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, d0, d1, d2, d3, d4, d5, d6, d7 );\ Py_INCREF( Py_None );\ return Py_None;\ } BGL_PL_FUNC_D( set_font_size, pl_ffontsize_r ); BGL_PL_FUNC_D( set_line_size, pl_flinewidth_r ); BGL_PL_FUNC_D( set_string_angle, pl_ftextangle_r ); BGL_PL_FUNC_DD( move, pl_fmove_r ); BGL_PL_FUNC_DD( lineto, pl_fcont_r ); BGL_PL_FUNC_DD( linetorel, pl_fcontrel_r ); BGL_PL_FUNC_DDD( circle, pl_fcircle_r ); BGL_PL_FUNC_DDDD( line, pl_fline_r ) BGL_PL_FUNC_DDDD( rect, pl_fbox_r ) BGL_PL_FUNC_DDDD( space, pl_fspace_r ) BGL_PL_FUNC_DDDDD( ellipse, pl_fellipse_r ) BGL_PL_FUNC_DDDDDD( arc, pl_farc_r ) BGL_PL_FUNC_DDDDDDDD( clipped_line, clipped_pl_fline_r ) /****************************************************************************** */ #define BGL_PL_FUNC_S(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ char *s0;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Os", &o, &s0 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ FUNCTION ( (plPlotter *) vptr, s0 );\ Py_INCREF( Py_None );\ return Py_None;\ } BGL_PL_FUNC_S( set_colorname_bg, pl_bgcolorname_r ); BGL_PL_FUNC_S( set_colorname_fg, pl_colorname_r ); BGL_PL_FUNC_S( set_colorname_fill, pl_fillcolorname_r ); BGL_PL_FUNC_S( set_colorname_pen, pl_pencolorname_r ); BGL_PL_FUNC_S( set_fill_type, pl_fillmod_r ); BGL_PL_FUNC_S( set_font_type, pl_fontname_r ); BGL_PL_FUNC_S( set_join_type, pl_joinmod_r ); BGL_PL_FUNC_S( set_line_type, pl_linemod_r ); /****************************************************************************** * color functions */ #define BGL_PL_FUNC_COLOR(NAME,FUNCTION)\ static PyObject *\ NAME ( PyObject *self, PyObject *args )\ {\ PyObject *o;\ double d0, d1, d2;\ int r, g, b;\ void *vptr;\ \ if ( !PyArg_ParseTuple( args, "Oddd", &o, &d0, &d1, &d2 ) )\ return NULL;\ vptr = (void *) PyCObject_AsVoidPtr( o );\ \ r = (int) floor( d0*65535 );\ g = (int) floor( d1*65535 );\ b = (int) floor( d2*65535 );\ \ FUNCTION ( (plPlotter *) vptr, r, g, b );\ Py_INCREF( Py_None );\ return Py_None;\ } BGL_PL_FUNC_COLOR( set_color_bg, pl_bgcolor_r ) BGL_PL_FUNC_COLOR( set_color_fg, pl_color_r ) BGL_PL_FUNC_COLOR( set_color_fill, pl_fillcolor_r ) BGL_PL_FUNC_COLOR( set_color_pen, pl_pencolor_r ) /****************************************************************************** */ static PyObject * string( PyObject *self, PyObject *args ) { PyObject *o; int i0, i1; char *s0; void *vptr; if ( !PyArg_ParseTuple( args, "Oiis", &o, &i0, &i1, &s0 ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl_alabel_r( (plPlotter *) vptr, i0, i1, s0 ); Py_INCREF( Py_None ); return Py_None; } static PyObject * get_string_width( PyObject *self, PyObject *args ) { PyObject *o; char *s0; void *vptr; double width; if ( !PyArg_ParseTuple( args, "Os", &o, &s0 ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); width = pl_flabelwidth_r( (plPlotter *) vptr, s0 ); return Py_BuildValue( "d", width ); } /****************************************************************************** * vector routines */ static void _symbol_begin( plPlotter *pl, int type, double size ) { if ( type > 31 ) { pl_savestate_r( pl ); pl_ffontsize_r( pl, size ); } } static void _symbol_draw( plPlotter *pl, double x, double y, int type, double size ) { if ( type > 31 ) { char type_str[2]; type_str[0] = type; type_str[1] = '\0'; pl_fmove_r( pl, x, y ); pl_alabel_r( pl, 'c', 'c', type_str ); } else { pl_fmarker_r( pl, x, y, type, size ); } } static void _symbol_end( plPlotter *pl, int type, double size ) { if ( type > 31 ) pl_restorestate_r( pl ); } static PyObject * symbols( PyObject *self, PyObject *args ) { PyObject *o, *ox, *oy; PyArrayObject *x, *y; double d0; int i0, i, n; void *vptr; plPlotter *pl; if ( !PyArg_ParseTuple( args, "OOOid", &o, &ox, &oy, &i0, &d0 ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; x = (PyArrayObject *) PyArray_ContiguousFromObject( ox, PyArray_DOUBLE, 1, 1 ); y = (PyArrayObject *) PyArray_ContiguousFromObject( oy, PyArray_DOUBLE, 1, 1 ); if ( x == NULL || y == NULL ) goto quit; n = MIN( x->dimensions[0], y->dimensions[0] ); _symbol_begin( pl, i0, d0 ); for ( i = 0; i < n; i++ ) _symbol_draw( pl, PyArray_1D(x,i), PyArray_1D(y,i), i0, d0 ); _symbol_end( pl, i0, d0 ); quit: Py_XDECREF(x); Py_XDECREF(y); Py_INCREF( Py_None ); return Py_None; } static PyObject * clipped_symbols( PyObject *self, PyObject *args ) { PyObject *o, *ox, *oy; PyArrayObject *x, *y; double xmin, xmax, ymin, ymax; double d0; int i0, i, n; void *vptr; plPlotter *pl; double px, py; if ( !PyArg_ParseTuple( args, "OOOiddddd", &o, &ox, &oy, &i0, &d0, &xmin, &xmax, &ymin, &ymax ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; x = (PyArrayObject *) PyArray_ContiguousFromObject( ox, PyArray_DOUBLE, 1, 1 ); y = (PyArrayObject *) PyArray_ContiguousFromObject( oy, PyArray_DOUBLE, 1, 1 ); if ( x == NULL || y == NULL ) goto quit; n = MIN( x->dimensions[0], y->dimensions[0] ); _symbol_begin( pl, i0, d0 ); for ( i = 0; i < n; i++ ) { px = PyArray_1D(x,i); py = PyArray_1D(y,i); if ( px >= xmin && px <= xmax && py >= ymin && py <= ymax ) _symbol_draw( pl, px, py, i0, d0 ); } _symbol_end( pl, i0, d0 ); quit: Py_XDECREF(x); Py_XDECREF(y); Py_INCREF( Py_None ); return Py_None; } static PyObject * clipped_colored_symbols( PyObject *self, PyObject *args ) { PyObject *o, *ox, *oy, *oc; PyArrayObject *x, *y, *c; double xmin, xmax, ymin, ymax; double d0; int i0, i, n; void *vptr; plPlotter *pl; double px, py; int r, g, b; if ( !PyArg_ParseTuple( args, "OOOOiddddd", &o, &ox, &oy, &oc, &i0, &d0, &xmin, &xmax, &ymin, &ymax ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; x = (PyArrayObject *) PyArray_ContiguousFromObject( ox, PyArray_DOUBLE, 1, 1 ); y = (PyArrayObject *) PyArray_ContiguousFromObject( oy, PyArray_DOUBLE, 1, 1 ); c = (PyArrayObject *) PyArray_ContiguousFromObject( oc, PyArray_DOUBLE, 2, 2 ); if ( x == NULL || y == NULL || c == NULL ) goto quit; n = MIN( x->dimensions[0], y->dimensions[0] ); n = MIN( n, c->dimensions[0] ); /* printf("c dims %dx%d first rgb %g,%g,%g\n", * c->dimensions[0], c->dimensions[1], * PyArray_2D(c,0,0),PyArray_2D(c,0,1),PyArray_2D(c,0,2) ); */ _symbol_begin( pl, i0, d0 ); for ( i = 0; i < n; i++ ) { px = PyArray_1D(x,i); py = PyArray_1D(y,i); if ( px >= xmin && px <= xmax && py >= ymin && py <= ymax ) { r = (int) floor( PyArray_2D(c,i,0)*65535 ); g = (int) floor( PyArray_2D(c,i,1)*65535 ); b = (int) floor( PyArray_2D(c,i,2)*65535 ); pl_fillcolor_r( (plPlotter *) vptr, r, g, b ); pl_pencolor_r( (plPlotter *) vptr, r, g, b ); _symbol_draw( pl, px, py, i0, d0 ); } } _symbol_end( pl, i0, d0 ); quit: Py_XDECREF(x); Py_XDECREF(y); Py_XDECREF(c); Py_INCREF( Py_None ); return Py_None; } /* * Draw a density plot -- * Given a grid of intensity values, plot uniform squares tiling * the region (xmin, ymin) to (xmax, ymax). * */ static PyObject * density_plot( PyObject *self, PyObject *args ) { PyObject *o, *ogrid; PyArrayObject *grid; double xmin, xmax, ymin, ymax; void *vptr; plPlotter *pl; double px, py, dx, dy; int xi, yi, xn, yn; int r, g, b; if ( !PyArg_ParseTuple( args, "OOdddd", &o, &ogrid, &xmin, &xmax, &ymin, &ymax ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; grid = (PyArrayObject *) PyArray_ContiguousFromObject( ogrid, PyArray_DOUBLE, 2, 2 ); if ( grid == NULL ) goto quit; xn = grid->dimensions[0]; yn = grid->dimensions[1]; dx = (xmax - xmin) / xn; dy = (ymax - ymin) / yn; /* printf("grid dims %dx%d from (%g,%g) to (%g,%g) first row %g,%g,%g,...\n", * grid->dimensions[0], grid->dimensions[1], * xmin, ymin, xmax, ymax, * PyArray_2D(grid,0,0),PyArray_2D(grid,0,1),PyArray_2D(grid,0,2) ); */ for ( xi=0, px=xmin; xi < xn; xi++, px+=dx ) { for ( yi=0, py=ymin; yi < yn; yi++, py+=dy ) { r=g=b = (int) floor( PyArray_2D(grid,xi,yi)*65535 ); pl_filltype_r ( (plPlotter *) vptr, 1.0 ); pl_fillcolor_r( (plPlotter *) vptr, r, g, b ); pl_pencolor_r ( (plPlotter *) vptr, r, g, b ); pl_fbox_r( pl, px, py, px+dx, py+dy ); } } quit: Py_XDECREF(grid); Py_INCREF( Py_None ); return Py_None; } static PyObject * color_density_plot( PyObject *self, PyObject *args ) { PyObject *o, *ogrid; PyArrayObject *grid; double xmin, xmax, ymin, ymax; void *vptr; plPlotter *pl; double px, py, dx, dy; int xi, yi, xn, yn; int r, g, b; if ( !PyArg_ParseTuple( args, "OOdddd", &o, &ogrid, &xmin, &xmax, &ymin, &ymax ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; grid = (PyArrayObject *) PyArray_ContiguousFromObject( ogrid, PyArray_DOUBLE, 3, 3 ); if ( grid == NULL ) goto quit; if ( grid->dimensions[2] != 3) { printf("Expect a NxMx3 array for densgrid"); goto quit; } xn = grid->dimensions[0]; yn = grid->dimensions[1]; dx = (xmax - xmin) / xn; dy = (ymax - ymin) / yn; /* printf("grid dims %dx%d from (%g,%g) to (%g,%g) first elt %g,%g,%g,...\n", * grid->dimensions[0], grid->dimensions[1], * xmin, ymin, xmax, ymax, * PyArray_3D(grid,0,0,0),PyArray_3D(grid,0,0,1),PyArray_3D(grid,0,0,2) ); */ for ( xi=0, px=xmin; xi < xn; xi++, px+=dx ) { for ( yi=0, py=ymin; yi < yn; yi++, py+=dy ) { r = (int) floor( PyArray_3D(grid,xi,yi,0)*65535 ); g = (int) floor( PyArray_3D(grid,xi,yi,1)*65535 ); b = (int) floor( PyArray_3D(grid,xi,yi,2)*65535 ); pl_filltype_r ( (plPlotter *) vptr, 1.0 ); pl_fillcolor_r( (plPlotter *) vptr, r, g, b ); pl_pencolor_r ( (plPlotter *) vptr, r, g, b ); pl_fbox_r( pl, px, py, px+dx, py+dy ); } } quit: Py_XDECREF(grid); Py_INCREF( Py_None ); return Py_None; } static PyObject * curve( PyObject *self, PyObject *args ) { PyObject *o, *ox, *oy; PyArrayObject *x, *y; int i, n; void *vptr; plPlotter *pl; if ( !PyArg_ParseTuple( args, "OOO", &o, &ox, &oy ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; x = (PyArrayObject *) PyArray_ContiguousFromObject( ox, PyArray_DOUBLE, 1, 1 ); y = (PyArrayObject *) PyArray_ContiguousFromObject( oy, PyArray_DOUBLE, 1, 1 ); if ( x == NULL || y == NULL ) goto quit; n = MIN( x->dimensions[0], y->dimensions[0] ); if ( n <= 0 ) goto quit; pl_fmove_r( pl, PyArray_1D(x,0), PyArray_1D(y,0) ); for ( i = 1; i < n; i++ ) pl_fcont_r( pl, PyArray_1D(x,i), PyArray_1D(y,i) ); pl_endpath_r( pl ); quit: Py_XDECREF(x); Py_XDECREF(y); Py_INCREF( Py_None ); return Py_None; } static PyObject * clipped_curve( PyObject *self, PyObject *args ) { PyObject *o, *ox, *oy; PyArrayObject *x, *y; double xmin, xmax, ymin, ymax; int i, n; void *vptr; plPlotter *pl; if ( !PyArg_ParseTuple( args, "OOOdddd", &o, &ox, &oy, &xmin, &xmax, &ymin, &ymax ) ) return NULL; vptr = (void *) PyCObject_AsVoidPtr( o ); pl = (plPlotter *) vptr; x = (PyArrayObject *) PyArray_ContiguousFromObject( ox, PyArray_DOUBLE, 1, 1 ); y = (PyArrayObject *) PyArray_ContiguousFromObject( oy, PyArray_DOUBLE, 1, 1 ); if ( x == NULL || y == NULL ) goto quit; n = MIN( x->dimensions[0], y->dimensions[0] ); if ( n <= 0 ) goto quit; for ( i = 0; i < n-1; i++ ) { clipped_pl_fline_r( pl, xmin, xmax, ymin, ymax, PyArray_1D(x,i), PyArray_1D(y,i), PyArray_1D(x,i+1), PyArray_1D(y,i+1) ); } pl_endpath_r( pl ); quit: Py_XDECREF(x); Py_XDECREF(y); Py_INCREF( Py_None ); return Py_None; } /***************************************************************************** * module init */ static PyMethodDef LibplotMethods[] = { { "new", new, METH_VARARGS }, /* () */ { "clear", clear, METH_VARARGS }, { "end_page", end_page, METH_VARARGS }, { "delete", delete, METH_VARARGS }, { "flush", flush, METH_VARARGS }, { "gsave", gsave, METH_VARARGS }, { "grestore", grestore, METH_VARARGS }, { "begin_page", begin_page, METH_VARARGS }, /* (i) */ { "set_fill_level", set_fill_level, METH_VARARGS }, /* (d) */ { "set_font_size", set_font_size, METH_VARARGS }, { "set_line_size", set_line_size, METH_VARARGS }, { "set_string_angle", set_string_angle, METH_VARARGS }, /* (dd) */ { "move", move, METH_VARARGS }, { "lineto", lineto, METH_VARARGS }, { "linetorel", linetorel, METH_VARARGS }, /* (ddd) */ { "circle", circle, METH_VARARGS }, /* (dddd) */ { "line", line, METH_VARARGS }, { "rect", rect, METH_VARARGS }, { "space", space, METH_VARARGS }, /* (ddddd) */ { "ellipse", ellipse, METH_VARARGS }, /* (dddddd) */ { "arc", arc, METH_VARARGS }, /* (dddddddd) */ { "clipped_line", clipped_line, METH_VARARGS }, /* (s) */ { "set_colorname_bg", set_colorname_bg, METH_VARARGS }, { "set_colorname_fg", set_colorname_fg, METH_VARARGS }, { "set_colorname_fill", set_colorname_fill, METH_VARARGS }, { "set_colorname_pen", set_colorname_pen, METH_VARARGS }, { "set_fill_type", set_fill_type, METH_VARARGS }, { "set_font_type", set_font_type, METH_VARARGS }, { "set_join_type", set_join_type, METH_VARARGS }, { "set_line_type", set_line_type, METH_VARARGS }, /* color */ { "set_color_bg", set_color_bg, METH_VARARGS }, { "set_color_fg", set_color_fg, METH_VARARGS }, { "set_color_fill", set_color_fill, METH_VARARGS }, { "set_color_pen", set_color_pen, METH_VARARGS }, { "string", string, METH_VARARGS }, { "get_string_width", get_string_width, METH_VARARGS }, { "symbols", symbols, METH_VARARGS }, { "curve", curve, METH_VARARGS }, { "clipped_symbols", clipped_symbols, METH_VARARGS }, { "clipped_curve", clipped_curve, METH_VARARGS }, { "clipped_colored_symbols", clipped_colored_symbols, METH_VARARGS }, { "density_plot", density_plot, METH_VARARGS }, { "color_density_plot", color_density_plot, METH_VARARGS }, { NULL, NULL } }; void initlibplot( void ) { Py_InitModule( "libplot", LibplotMethods ); import_array(); } python2-biggles-1.6.6/src/libplot/tex2libplot.pyc0000644000175100017510000001735311357716146021024 0ustar noltanolta `=c@sMddkZddkZdd6dYZhdd<dd<dd <d d <d d <dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<d d!<d"d"<d#d<d#dd?<d@dA<dBdC<dDdE<dFdG<dHdI<dJdK<dLdM<dNdO<dPdQ<dRdS<dTdU<dVdW<dXdY<dZd[<d\d]<d^d_<d`da<dbdc<ddde<dfdg<dhdi<djdk<dldm<dndo<dpdq<drds<dtdu<dvdw<dxdy<dzd{<d|d}<d~d<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dWd<d4d<dd<dd<dd<dd<dd<dd<d0d<d2d<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<d d <d d <d d<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd <dd!<d"d#<d$d%<dd&<dd'<dd(<d)d*<d)d+<d)d,<d)d-=s\geqs>>s\ggs\SSs\supsett|s\mids \parallels\==s\equivs\aps\sims\~-s\simeqs\~~s\approxs\=~s\congs\pts\proptos\pps\perps\<-s \leftarrows\lAs \Leftarrows\->s \rightarrows\rAs \Rightarrows\<>s\leftrightarrows\hAs\Leftrightarrows\uas\uparrows\uAs\Uparrows\das \downarrows\dAs \Downarrowt[s\lbracks\lbraces\las\langlet]s\rbracks\rbraces\ras\rangles\!=s\nes\neqs\les\ges\tos\getss\ANs\lands\ORs\lors\lnots\verts\Verts\des\degrees\degs\degrs\arcdegcCs0ti|o t|Snti||SdS(N(t_text_token_dictthas_keyt_common_token_dicttget(R((s../src/libplot/tex2libplot.pytmap_text_tokenYs cCs0ti|o t|Snti||SdS(N(t_math_token_dictR%R&R'(R((s../src/libplot/tex2libplot.pytmap_math_token_s cCsyd}d}xf|i}|djoPn|djo d}q|djoPq|t|}|pPqq|S(NRiRiR(RRR*(tlexertoutputt bracketmodeR((s../src/libplot/tex2libplot.pyt math_groupes     s\f0s\f1s\f2s\f3c Csd}d}g}d}t|}x|i}|djoPnd}|djo | }nw|djo|i|nY|djo1|i}||jo|}t|}qn|djod}t|}n|djod }t|}n|d jod }t|}n|pt|}n|d jo=d t|d}|idjod|d}qnW|djo=dt|d}|id jod|d}qn t |}||}q'|S(NRiiRRRs\rms\itis\bfiRs\sbs\ebt^s\mks\rts\sps\ep( RRRRR t font_codeR(R.RR*( RR,tmathmodet font_stacktfontR+RRtold_font((s../src/libplot/tex2libplot.pyt tex2libplotysR                (( RtstringRR&R$R)R(R*R.R0R5(((s../src/libplot/tex2libplot.pyss^'                                                                                                                                                                       python2-biggles-1.6.6/src/libplot/Makefile.win0000644000175100017510000000410110611710022020231 0ustar noltanolta# Makefile for libplot.pyd for the Biggles plot library on Microsoft Visual C/C++ 6 # # Targets: # TARGET: build the target libplot.pyd # ALL (default): same as TARGET # CLEAN: delete all generated files # REBUILD: CLEAN + TARGET # LISTDLL: list the contents of the dll (pyd) PROJ = libplot TARGET = $(PROJ).pyd # Locations of required files # Python header location PYTHONDIR = $(PYTHONHOME) # numpy header location NUMPYDIR = $(PYTHONHOME)\Lib\site-packages\numpy # This is the location of plot.h (which mysteriously doesn't come bundled with the # win32 Biggles distribution) PLOTUTILDIR = . # Check that the given file locations exist !if !exist($(PYTHONDIR)) ! ERROR PYTHONDIR ($(PYTHONDIR)) doesn't exist. Aborting. !endif !if !exist($(NUMPYDIR)) ! ERROR NUMPYDIR ($(NUMPYDIR)) doesn't exist. Aborting. !endif !if !exist($(PLOTUTILDIR)) ! ERROR PLOTUTILDIR ($(PLOTUTILDIR)) doesn't exist. Aborting. !endif INCLUDE = $(NUMPYDIR);$(PYTHONDIR)\include;$(PLOTUTILDIR);$(INCLUDE) # Define the targets ALL: $(TARGET) TARGET: $(TARGET) CPP = cl.exe CPPFLAGS = /nologo /MD /W3 /GX /O2 /DWIN32 /DNDEBUG /D_WINDOWS /D_USRDLL LINK_CMD = link LINK_FLAGS = /nologo /dll /incremental:no /machine:I386 /LIBPATH:$(PYTHONDIR)\libs $(PROJ).obj: $(PROJ).c $(CPP) /c $(CPPFLAGS) $** LIBPLOTEXPORTSIMPLIB = $(PROJ)exports.lib EXPORTSFILENAME = $(LIBPLOTEXPORTSIMPLIB:.lib=.exp) # Build the libplot import library $(LIBPLOTEXPORTSIMPLIB): $$(@B).def lib /NOLOGO /MACHINE:IX86 /DEF:$? /OUT:$@ $(TARGET): $(LIBPLOTEXPORTSIMPLIB) $(PROJ).obj $(LINK_CMD) $(LINK_FLAGS) $** /export:init$(PROJ) /out:$@ CLEAN: if exist $(PROJ).obj del $(PROJ).obj if exist $(PROJ).lib del $(PROJ).lib if exist $(PROJ).exp del $(PROJ).exp if exist $(TARGET) del $(TARGET) if exist $(LIBPLOTEXPORTSIMPLIB) del $(LIBPLOTEXPORTSIMPLIB) if exist $(EXPORTSFILENAME) del $(EXPORTSFILENAME) REBUILD: CLEAN TARGET LISTDLL: @dumpbin /EXPORTS $(TARGET) # end of file python2-biggles-1.6.6/src/libplot/renderer.pyc0000644000175100017510000003761111357716146020361 0ustar noltanolta M@c@s=ddkZddkZeZddklZdZdZdZdd!dYZdd Zd Z d Z d Z hd d<dd<dds    icCsSt|d}||d?d@}||d?d@}||d?d@}|||fS(Niiii(tfloat(t hextriplettscaleRtrRtb((s../src/libplot/renderer.pyt _hexcolorWs cCs\t|tdjoti||n,t|\}}}ti||||dS(Nt(ttypetrawtset_colorname_fgR-t set_color_fg(tpltcolorR+RR,((s../src/libplot/renderer.pyt _set_color^scCs\t|tdjoti||n,t|\}}}ti||||dS(NR.(R/R0tset_colorname_penR-t set_color_pen(R3R4R+RR,((s../src/libplot/renderer.pyt_set_pen_colorescCs\t|tdjoti||n,t|\}}}ti||||dS(NR.(R/R0tset_colorname_fillR-tset_color_fill(R3R4R+RR,((s../src/libplot/renderer.pyt_set_fill_colorlstdottedtdott shortdashedtdashtdashedcCs&ti||}ti||dS(N(t _pl_line_typeR R0t set_line_type(R3R/tpl_type((s../src/libplot/renderer.pyt_set_line_typeystLibplotRenderercBs eZddtdtdZdZdZdZdZdZhe d<e d<e d <e d <e id <e id <e id <e id<e id<e idd?<d@dA<dBdC<dDdE<dFdG<dHdI<dJdK<dLdM<dNdO<dPdQ<dRdS<dTdU<dVdW<dXdY<dZd[<d\d]ti|i|d|d|d|d|d|ddS(Nii(R0tarcR3(RtcRR ((s../src/libplot/renderer.pyRvsitnoneiR=itplusitasteriskiRqitcrossitsquareittriangleitdiamondi tstari sinverted trianglei t starbursti s fancy plusi s fancy crossis fancy squareis fancy diamondis filled circleis filled squareisfilled triangleisfilled diamondisfilled inverted triangleisfilled fancy squareisfilled fancy diamondishalf filled circleishalf filled squareishalf filled triangleishalf filled diamondishalf filled inverted triangleishalf filled fancy squareishalf filled fancy diamonditoctagonisfilled octagoncCs"|i|dg|dgdS(Nii(tsymbols(RR((s../src/libplot/renderer.pytsymbolsc Csd}d}|iid|}|iid|}t|djot|d}ntii|}|id}|djo ti|i ||||n9ti |i |||||d|d|d|d  dS( NR|g{Gz?t symboltypet symbolsizeiiRlii( RNR RtordREt _LibplotRenderer__pl_symbol_typeR'R0RR3tclipped_symbols( RtxtytDEFAULT_SYMBOL_TYPEtDEFAULT_SYMBOL_SIZEttype_strtsizeR/Ro((s../src/libplot/renderer.pyRs  c Csd}d}|iid|}|iid|}t|djot|d}ntii|}|id} | djo ti|i ||||n<ti |i |||||| d| d| d| d  dS( NR|g{Gz?RRiiRlii( RNR RRRERR'R0tcolored_symbolsR3tclipped_colored_symbols( RRRRwRRRRR/Ro((s../src/libplot/renderer.pyRs  cCs;|\\}}\}}ti|i|||||dS(N(R0t density_plotR3(Rtdensgridt.2txmintymintxmaxtymax((s../src/libplot/renderer.pyR#scCs;|\\}}\}}ti|i|||||dS(N(R0tcolor_density_plotR3(RRRRRRR((s../src/libplot/renderer.pyR'sc Csl|id}|djoti|i||n3ti|i|||d|d|d|ddS(NRliiii(R R'R0tcurveR3t clipped_curve(RRRRo((s../src/libplot/renderer.pyR,s  cCs|}|id}|dj ojt|d|dd }t|d|dd}t|d|dd }t|d|dd}n|i|dt|i|ddS(NRliiiii(R R'RRitmapRj(RtpointstptsRo((s../src/libplot/renderer.pyR 4s RwtcenterRtbaselinetltleftR+trightttttopR,tbottomcCst|}|iidd}|iidd}tii|}tii|}ti|i|d|dti|i|||dS(Nt texthalignRt textvalignii( RRNR REt_LibplotRenderer__pl_text_alignR0RiR3tstring(RRtstrtplstrthstrtvstrthnumtvnum((s../src/libplot/renderer.pyttextJs cCst|}ti|i|S(N(RR0tget_string_widthR3(RRR((s../src/libplot/renderer.pyt textwidthSs cCs|iidS(NR_(RNR (RR((s../src/libplot/renderer.pyt textheightWsN(.R%R&R'RRSRRRURVRWR5R8R;RDR0t set_line_sizetset_fill_levelt set_fill_typet set_font_typet set_font_sizetset_string_angleRaRR RfRhRiRjRkRmRpRqRrRvRRRRRRRR RRRRR(((s../src/libplot/renderer.pyRE}s                                                                 tNonInteractiveScreenRenderercBseZdZRS(cCsQd}||f}hd||fd<dd<}ti|||d|dS(Nis%dx%dt BITMAPSIZEtnotVANISH_ON_DELETERF(ii(RER(RtwidththeightRJRKRL((s../src/libplot/renderer.pyR\s   (R%R&R(((s../src/libplot/renderer.pyRZstInteractiveScreenRenderercBs#eZdZdZdZRS(cCsQd}||f}hd||fd<dd<}ti|||d|dS(Nis%dx%dRtyesRRF(ii(RER(RRRRJRKRL((s../src/libplot/renderer.pyRgs   cCsti|idS(N(R0tflushR3(R((s../src/libplot/renderer.pyRUpscCsti|idS(N(R0RR3(R((s../src/libplot/renderer.pyRVss(R%R&RRURV(((s../src/libplot/renderer.pyRes iicCsP|djo2tdjot||antitSnt||SdS(Ni(t_saved_screen_rendererR'RRRR(t persistentRR((s../src/libplot/renderer.pytScreenRendererxs    cCsddk}|idi|}t|id}|id}hdd<dd<dd <d d <}t|||}|S( Nis([\d.]+)([^\s]+)iiiHtintptgGz@tmmgY<@tcm(tretcompiletmatchR(tgrouptint(RRtmtnum_xxtunitstxx2pttnum_pt((s../src/libplot/renderer.pyt_str_size_to_ptss *t PSRenderercBseZddddZRS(R.c Ksd}t|t|f}d|||f}x0|iD]"\} } |d| d| }q>Wh|d<} ti|||d| |dS(Nis%s,xsize=%s,ysize=%st,t=tPAGESIZEtps(ii(RtitemsRER( RRMtpaperRRtkwRJRKtpagesizeRbtvalRL((s../src/libplot/renderer.pyRs (R%R&R(((s../src/libplot/renderer.pyRst ImageRenderercBseZdZRS(cCsKd}||f}hd||fd<}ti||||||dS(Nis%dx%dR(ii(RER(RR/RRRMRJRKRL((s../src/libplot/renderer.pyRs (R%R&R(((s../src/libplot/renderer.pyRs(((tlibplottmathR0RRR RRR-R5R8R;RARDRERRR'RRRRR(((s../src/libplot/renderer.pyss.             python2-biggles-1.6.6/src/libplot/renderer.py0000644000175100017510000002501610023200775020173 0ustar noltanolta# # $Id: renderer.py,v 1.17 2004/03/08 23:30:05 mrnolta Exp $ # # Copyright (C) 2000-2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import libplot, math raw = libplot from tex2libplot import tex2libplot ## polygon clipping def sh_inside( p, dim, boundary, side ): return side*p[dim] >= side*boundary def sh_intersection( s, p, dim, boundary ): mid = not dim g = 0. if p[dim] != s[dim]: g = (boundary - s[dim])/(p[dim] - s[dim]) q = [0,0] q[dim] = boundary q[mid] = s[mid] + g*(p[mid] - s[mid]) return q[0], q[1] def sutherland_hodgman( polygon, dim, boundary, side ): out = [] s = polygon[-1] s_inside = sh_inside( s, dim, boundary, side ) for p in polygon: p_inside = sh_inside( p, dim, boundary, side ) crosses = (p_inside and not s_inside) or \ (not p_inside and s_inside) if crosses: out.append( sh_intersection(s, p, dim, boundary) ) if p_inside: out.append( p ) s = p s_inside = p_inside return out class RendererState: def __init__( self ): self.current = {} self.saved = [] def set( self, name, value ): self.current[name] = value def get( self, name, notfound=None ): if self.current.has_key(name): return self.current[name] for i in range(len(self.saved)): d = self.saved[i] if d.has_key(name): return d[name] return notfound def save( self ): self.saved.insert( 0, self.current ) self.current = {} def restore( self ): self.current = self.saved.pop(0) def _hexcolor( hextriplet, scale=1 ): s = float(scale) / 0xff r = s * ((hextriplet >> 16) & 0xff) g = s * ((hextriplet >> 8) & 0xff) b = s * ((hextriplet >> 0) & 0xff) return r, g, b def _set_color( pl, color ): if type(color) == type(''): raw.set_colorname_fg( pl, color ) else: r,g,b = _hexcolor( color ) raw.set_color_fg( pl, r, g, b ) def _set_pen_color( pl, color ): if type(color) == type(''): raw.set_colorname_pen( pl, color ) else: r,g,b = _hexcolor( color ) raw.set_color_pen( pl, r, g, b ) def _set_fill_color( pl, color ): if type(color) == type(''): raw.set_colorname_fill( pl, color ) else: r,g,b = _hexcolor( color ) raw.set_color_fill( pl, r, g, b ) _pl_line_type = { "dot" : "dotted", "dash" : "shortdashed", "dashed" : "shortdashed", } def _set_line_type( pl, type ): pl_type = _pl_line_type.get( type, type ) raw.set_line_type( pl, pl_type ) class LibplotRenderer: def __init__( self, ll, ur, type='X', parameters=None, file=None ): self.lowerleft = ll self.upperright = ur self.pl = raw.new( type, parameters, file ) def open( self ): self.state = RendererState() raw.begin_page( self.pl ) apply( raw.space, \ (self.pl,) + self.lowerleft + self.upperright ) raw.clear( self.pl ) def clear( self ): raw.clear( self.pl ) def close( self ): if self.pl is not None: raw.end_page( self.pl ) def delete( self ): if self.pl is not None: raw.delete( self.pl ) self.pl = None def __del__( self ): self.delete() ## state commands __pl_style_func = { "color" : _set_color, "linecolor" : _set_pen_color, "fillcolor" : _set_fill_color, "linetype" : _set_line_type, "linewidth" : raw.set_line_size, "filltype" : raw.set_fill_level, "fillmode" : raw.set_fill_type, "fontface" : raw.set_font_type, "fontsize" : raw.set_font_size, "textangle" : raw.set_string_angle, } def set( self, key, value ): self.state.set( key, value ) if LibplotRenderer.__pl_style_func.has_key(key): method = LibplotRenderer.__pl_style_func[key] apply( method, (self.pl, value) ) def get( self, parameter, notfound=None ): return self.state.get( parameter, notfound ) def save_state( self ): self.state.save() raw.gsave( self.pl ) def restore_state( self ): self.state.restore() raw.grestore( self.pl ) ## drawing commands def move( self, p ): raw.move( self.pl, p[0], p[1] ) def lineto( self, p ): raw.lineto( self.pl, p[0], p[1] ) def linetorel( self, p ): raw.linetorel( self.pl, p[0], p[1] ) def line( self, p, q ): cr = self.get( "cliprect" ) if cr is None: raw.line( self.pl, p[0], p[1], q[0], q[1] ) else: raw.clipped_line( self.pl, \ cr[0], cr[1], cr[2], cr[3], \ p[0], p[1], q[0], q[1] ) def rect( self, p, q ): raw.rect( self.pl, p[0], p[1], q[0], q[1] ) def circle( self, p, r ): raw.circle( self.pl, p[0], p[1], r ) def ellipse( self, p, rx, ry, angle=0. ): raw.ellipse( self.pl, p[0], p[1], rx, ry, angle ) def arc( self, c, p, q ): raw.arc( self.pl, c[0], c[1], p[0], p[1], q[0], q[1] ) __pl_symbol_type = { "none" : 0, "dot" : 1, "plus" : 2, "asterisk" : 3, "circle" : 4, "cross" : 5, "square" : 6, "triangle" : 7, "diamond" : 8, "star" : 9, "inverted triangle" : 10, "starburst" : 11, "fancy plus" : 12, "fancy cross" : 13, "fancy square" : 14, "fancy diamond" : 15, "filled circle" : 16, "filled square" : 17, "filled triangle" : 18, "filled diamond" : 19, "filled inverted triangle" : 20, "filled fancy square" : 21, "filled fancy diamond" : 22, "half filled circle" : 23, "half filled square" : 24, "half filled triangle" : 25, "half filled diamond" : 26, "half filled inverted triangle" : 27, "half filled fancy square" : 28, "half filled fancy diamond" : 29, "octagon" : 30, "filled octagon" : 31, } def symbol( self, p ): self.symbols( [p[0]], [p[1]] ) def symbols( self, x, y ): DEFAULT_SYMBOL_TYPE = "square" DEFAULT_SYMBOL_SIZE = 0.01 type_str = self.state.get( "symboltype", DEFAULT_SYMBOL_TYPE ) size = self.state.get( "symbolsize", DEFAULT_SYMBOL_SIZE ) if len(type_str) == 1: type = ord(type_str[0]) else: type = LibplotRenderer.__pl_symbol_type.get( type_str ) cr = self.get( "cliprect" ) if cr is None: raw.symbols( self.pl, x, y, type, size ) else: raw.clipped_symbols( self.pl, x, y, type, size, cr[0], cr[1], cr[2], cr[3] ) def colored_symbols( self, x, y, c ): DEFAULT_SYMBOL_TYPE = "square" DEFAULT_SYMBOL_SIZE = 0.01 type_str = self.state.get( "symboltype", DEFAULT_SYMBOL_TYPE ) size = self.state.get( "symbolsize", DEFAULT_SYMBOL_SIZE ) if len(type_str) == 1: type = ord(type_str[0]) else: type = LibplotRenderer.__pl_symbol_type.get( type_str ) cr = self.get( "cliprect" ) if cr is None: # This will cause an error: not written yet raw.colored_symbols( self.pl, x, y, type, size ) else: raw.clipped_colored_symbols( self.pl, x, y, c, type, size, cr[0], cr[1], cr[2], cr[3] ) def density_plot( self, densgrid, ((xmin,ymin), (xmax,ymax)) ): raw.density_plot( self.pl, densgrid, xmin, xmax, ymin, ymax ) def color_density_plot( self, densgrid, ((xmin,ymin), (xmax,ymax)) ): raw.color_density_plot( self.pl, densgrid, xmin, xmax, ymin, ymax ) def curve( self, x, y ): cr = self.get( "cliprect" ) if cr is None: raw.curve( self.pl, x, y ) else: raw.clipped_curve( self.pl, x, y, cr[0], cr[1], cr[2], cr[3] ) def polygon( self, points ): pts = points cr = self.get( "cliprect" ) if cr is not None: pts = sutherland_hodgman( pts, 0, cr[0], +1 ) pts = sutherland_hodgman( pts, 0, cr[1], -1 ) pts = sutherland_hodgman( pts, 1, cr[2], +1 ) pts = sutherland_hodgman( pts, 1, cr[3], -1 ) self.move( pts[0] ) map( self.lineto, pts[1:] ) ## text commands __pl_text_align = { "center" : ord('c'), "baseline" : ord('x'), "left" : ord('l'), "right" : ord('r'), "top" : ord('t'), "bottom" : ord('b'), } def text( self, p, str ): plstr = tex2libplot( str ) hstr = self.state.get( "texthalign", "center" ) vstr = self.state.get( "textvalign", "center" ) hnum = LibplotRenderer.__pl_text_align.get( hstr ) vnum = LibplotRenderer.__pl_text_align.get( vstr ) raw.move( self.pl, p[0], p[1] ) raw.string( self.pl, hnum, vnum, plstr ) def textwidth( self, str ): plstr = tex2libplot( str ) return raw.get_string_width( self.pl, plstr ) def textheight( self, str ): return self.state.get( "fontsize" ) ## XXX: kludge? class NonInteractiveScreenRenderer( LibplotRenderer ): def __init__( self, width, height ): ll = 0, 0 ur = width, height parameters = { "BITMAPSIZE": "%dx%d" % (width, height), "VANISH_ON_DELETE": "no", } LibplotRenderer.__init__( self, ll, ur, "X", parameters ) class InteractiveScreenRenderer( LibplotRenderer ): def __init__( self, width, height ): ll = 0, 0 ur = width, height parameters = { "BITMAPSIZE": "%dx%d" % (width, height), "VANISH_ON_DELETE": "yes", } LibplotRenderer.__init__( self, ll, ur, "X", parameters ) def close( self ): raw.flush( self.pl ) def delete( self ): raw.flush( self.pl ) _saved_screen_renderer = None def ScreenRenderer( persistent=0, width=512, height=512 ): if persistent == 1: global _saved_screen_renderer if _saved_screen_renderer is None: _saved_screen_renderer \ = InteractiveScreenRenderer( width, height ) _saved_screen_renderer.clear() return _saved_screen_renderer else: return NonInteractiveScreenRenderer( width, height ) def _str_size_to_pts( str ): import re m = re.compile(r"([\d.]+)([^\s]+)").match(str) num_xx = float(m.group(1)) units = m.group(2) # convert to postscipt pt = in/72 xx2pt = { "in":72, "pt":1, "mm":2.835, "cm":28.35 } num_pt = int(num_xx*xx2pt[units]) return num_pt class PSRenderer( LibplotRenderer ): def __init__( self, file, paper="", width="", height="", **kw ): ll = 0, 0 ur = _str_size_to_pts(width), _str_size_to_pts(height) pagesize = "%s,xsize=%s,ysize=%s" % (paper,width,height) for key,val in kw.items(): pagesize = pagesize +","+ key +"="+ val parameters = { "PAGESIZE": pagesize } LibplotRenderer.__init__( self, ll, ur, "ps", parameters, file ) class ImageRenderer( LibplotRenderer ): def __init__( self, type, width, height, file ): ll = 0, 0 ur = width, height parameters = { "BITMAPSIZE": "%dx%d" % (width, height) } LibplotRenderer.__init__( self, ll, ur, type, parameters, file ) python2-biggles-1.6.6/src/libplot/tex2libplot.py0000644000175100017510000002170707530014727020651 0ustar noltanolta# # $Id: tex2libplot.py,v 1.5 2002/08/18 22:04:07 mrnolta Exp $ # # Copyright (C) 2000 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # # This is just a quick and dirty converter from simple TeX strings # to libplot Hershey font strings. Basically just a lookup table. # import re, string class TeXLexer: re_control_sequence = re.compile( r"^\\[a-zA-Z]+[ ]?|^\\[^a-zA-Z][ ]?" ) def __init__( self, str ): self.str = str self.len = len(str) self.pos = 0 self.token_stack = [] def get_token( self ): if self.pos == self.len: return None if len(self.token_stack) > 0: return self.token_stack.pop() str = self.str[self.pos:] m = self.re_control_sequence.match(str) if m is not None: token = m.group() self.pos = self.pos + len(token) ## consume trailing space if len(token) > 2 and token[-1] == ' ': token = token[:-1] else: token = str[0] self.pos = self.pos + 1 return token def put_token( self, token ): self.token_stack.append( token ) def peek( self ): token = self.get_token() self.put_token( token ) return token _common_token_dict = { r'\\' : '\\', r'\$' : r'$', r'\%' : r'%', r'\#' : r'#', r'\&' : r'&', # r'\~' : r'~', r'\{' : r'{', r'\}' : r'}', r'\_' : r'_', # r'\^' : r'^', r'~' : r' ', r'\/' : r'\r^', ## special letters (p52) # r'\oe' : r'', # r'\OE' : r'', r'\ae' : r'\ae', r'\AE' : r'\AE', r'\aa' : r'\oa', r'\AA' : r'\oA', r'\o' : r'\/o', r'\O' : r'\/O', # r'\l' : r'', # r'\L' : r'', r'\ss' : r'\ss', ## ignore stray brackets r'{' : r'', r'}' : r'', } _text_token_dict = { ## punctuation (p52) r'\`' : r'\`', r"\'" : r"\'", r'\^' : r'\^', r'\"' : r'\:', r'\~' : r'\~', r'\c' : r'\,', ## non-math symbols (p438) r'\S' : r'\sc', r'\P' : r'\ps', r'\dag' : r'\dg', r'\ddag' : r'\dd', } _math_token_dict = { r'*' : r'\**', ## spacing # r' ' : r'', r'\ ' : r' ', r'\quad' : r'\r1', # 1 em r'\qquad' : r'\r1\r1', # 2 em r'\,' : r'\r6', # 3/18 em # r'\>' : r'', # 4/18 em # r'\;' : r'', # 5/18 em r'\!' : r'\l6', # -1/6 em ## lowercase greek r'\alpha' : r'\*a', r'\beta' : r'\*b', r'\gamma' : r'\*g', r'\delta' : r'\*d', r'\epsilon' : r'\*e', # r'\varepsilon' : r'', r'\zeta' : r'\*z', r'\eta' : r'\*y', r'\theta' : r'\*h', r'\vartheta' : r'\+h', r'\iota' : r'\*i', r'\kappa' : r'\*k', r'\lambda' : r'\*l', r'\mu' : r'\*m', r'\nu' : r'\*n', r'\xi' : r'\*c', r'\pi' : r'\*p', # r'\varpi' : r'', r'\rho' : r'\*r', # r'\varrho' : r'', r'\sigma' : r'\*s', r'\varsigma' : r'\ts', r'\tau' : r'\*t', r'\upsilon' : r'\*u', r'\phi' : r'\*f', r'\varphi' : r'\+f', r'\chi' : r'\*x', r'\psi' : r'\*q', r'\omega' : r'\*w', ## uppercase greek r'\Alpha' : r'\*A', r'\Beta' : r'\*B', r'\Gamma' : r'\*G', r'\Delta' : r'\*D', r'\Epsilon' : r'\*E', r'\Zeta' : r'\*Z', r'\Eta' : r'\*Y', r'\Theta' : r'\*H', r'\Iota' : r'\*I', r'\Kappa' : r'\*K', r'\Lambda' : r'\*L', r'\Mu' : r'\*M', r'\Nu' : r'\*N', r'\Xi' : r'\*C', r'\Pi' : r'\*P', r'\Rho' : r'\*R', r'\Sigma' : r'\*S', r'\Tau' : r'\*T', r'\Upsilon' : r'\*U', r'\Phi' : r'\*F', r'\Chi' : r'\*X', r'\Psi' : r'\*Q', r'\Omega' : r'\*W', ## miscellaneous r'\aleph' : r'\Ah', r'\hbar' : r'\hb', r'\ell' : r'\#H0662', r'\wp' : r'\wp', r'\Re' : r'\Re', r'\Im' : r'\Im', r'\partial' : r'\pd', r'\infty' : r'\if', r'\prime' : r'\fm', r'\emptyset' : r'\es', r'\nabla' : r'\gr', r'\surd' : r'\sr', # r'\top' : r'', # r'\bot' : r'', r'\|' : r'\||', r'\angle' : r'\/_', # r'\triangle' : r'', r'\backslash' : r'\\', r'\forall' : r'\fa', r'\exists' : r'\te', r'\neg' : r'\no', # r'\flat' : r'', # r'\natural' : r'', # r'\sharp' : r'', r'\clubsuit' : r'\CL', r'\diamondsuit' : r'\DI', r'\heartsuit' : r'\HE', r'\spadesuit' : r'\SP', ## binary operations r'\pm' : r'\+-', r'\mp' : r'\-+', # r'\setminus' : r'', r'\cdot' : r'\md', r'\times' : r'\mu', r'\ast' : r'\**', # r'\star' : r'', # r'\diamond' : r'', # r'\circ' : r'', r'\bullet' : r'\bu', r'\div' : r'\di', r'\cap' : r'\ca', r'\cup' : r'\cu', # r'\uplus' : r'', # r'\sqcap' : r'', # r'\sqcup' : r'', # r'\triangleleft' : r'', # r'\triangleright' : r'', # r'\wr' : r'', # r'\bigcirc' : r'', # r'\bigtriangleup' : r'', # r'\bigtriangledown' : r'', # r'\vee' : r'', # r'\wedge' : r'', r'\oplus' : r'\c+', # r'\ominus' : r'', r'\otimes' : r'\c*', # r'\oslash' : r'', # r'\odot' : r'', r'\dagger' : r'\dg', r'\ddagger' : r'\dd', # r'\amalg' : r'', ## relations r'\leq' : r'\<=', # r'\prec' : r'', # r'\preceq' : r'', r'\ll' : r'<<', r'\subset' : r'\SB', # r'\subseteq' : r'', # r'\sqsubseteq' : r'', r'\in' : r'\mo', # r'\vdash' : r'', # r'\smile' : r'', # r'\frown' : r'', r'\geq' : r'\>=', # r'\succ' : r'', # r'\succeq' : r'', r'\gg' : r'>>', r'\supset' : r'\SS', # r'\supseteq' : r'', # r'\sqsupseteq' : r'', # r'\ni' : r'', # r'\dashv' : r'', r'\mid' : r'|', r'\parallel' : r'\||', r'\equiv' : r'\==', r'\sim' : r'\ap', r'\simeq' : r'\~-', # r'\asymp' : r'', r'\approx' : r'\~~', r'\cong' : r'\=~', # r'\bowtie' : r'', r'\propto' : r'\pt', # r'\models' : r'', # r'\doteq' : r'', r'\perp' : r'\pp', ## arrows r'\leftarrow' : r'\<-', r'\Leftarrow' : r'\lA', r'\rightarrow' : r'\->', r'\Rightarrow' : r'\rA', r'\leftrightarrow' : r'\<>', r'\Leftrightarrow' : r'\hA', # r'\mapsto' : r'', # r'\hookleftarrow' : r'', # r'\leftharpoonup' : r'', # r'\leftharpoondown' : r'', # r'\rightleftharpoons' : r'', # ... r'\uparrow' : r'\ua', r'\Uparrow' : r'\uA', r'\downarrow' : r'\da', r'\Downarrow' : r'\dA', # r'\updownarrow' : r'', # r'\Updownarrow' : r'', # r'\nearrow' : r'', # r'\searrow' : r'', # r'\swarrow' : r'', # r'\nwarrow' : r'', ## openings r'\lbrack' : r'[', r'\lbrace' : r'{', r'\langle' : r'\la', # r'\lfloor' : r'', # r'\lceil' : r'', ## closings r'\rbrack' : r']', r'\rbrace' : r'}', r'\rangle' : r'\ra', # r'\rfloor' : r'', # r'\rceil' : r'', ## alternate names r'\ne' : r'\!=', r'\neq' : r'\!=', r'\le' : r'\<=', r'\ge' : r'\>=', r'\to' : r'\->', r'\gets' : r'\<-', # r'\owns' : r'', r'\land' : r'\AN', r'\lor' : r'\OR', r'\lnot' : r'\no', r'\vert' : r'|', r'\Vert' : r'\||', ## extensions r'\degree' : r'\de', r'\deg' : r'\de', r'\degr' : r'\de', r'\arcdeg' : r'\de', } def map_text_token( token ): if _text_token_dict.has_key(token): return _text_token_dict[token] else: return _common_token_dict.get( token, token ) def map_math_token( token ): if _math_token_dict.has_key(token): return _math_token_dict[token] else: return _common_token_dict.get( token, token ) def math_group( lexer ): output = '' bracketmode = 0 while 1: token = lexer.get_token() if token is None: break if token == '{': bracketmode = 1 elif token == '}': break else: output = output + map_math_token( token ) if not bracketmode: break return output font_code = [ r'\f0', r'\f1', r'\f2', r'\f3' ] def tex2libplot( str ): output = '' mathmode = 0 font_stack = [] font = 1 lexer = TeXLexer( str ) while 1: token = lexer.get_token() if token is None: break append = '' if token == '$': mathmode = not mathmode elif token == '{': font_stack.append( font ) elif token == '}': old_font = font_stack.pop() if old_font != font: font = old_font append = font_code[font] elif token == r'\rm': font = 1 append = font_code[font] elif token == r'\it': font = 2 append = font_code[font] elif token == r'\bf': font = 3 append = font_code[font] elif not mathmode: append = map_text_token( token ) elif token == '_': append = r'\sb' + math_group(lexer) + r'\eb' if lexer.peek() == '^': append = r'\mk' + append + r'\rt' elif token == '^': append = r'\sp' + math_group(lexer) + r'\ep' if lexer.peek() == '_': append = r'\mk' + append + r'\rt' else: append = map_math_token( token ) output = output + append return output python2-biggles-1.6.6/src/libplot/__init__.pyc0000644000175100017510000000016111357716146020300 0ustar noltanolta ;c@sdS(N((((s../src/libplot/__init__.pysspython2-biggles-1.6.6/src/libplot/libplotexports.def0000644000175100017510000007061007554425070021601 0ustar noltanoltaLIBRARY libplot DESCRIPTION import library for Win32 plotutils v2.4.1-1 EXPORTS __miCreateETandAET @324 __miDrawArcs_r_internal @2 __miDrawLines_internal @3 __miDrawPoints_internal @4 __miDrawRectangles_internal @5 __miFillArcs_internal @6 __miFillConvexPoly @7 __miFillGeneralPoly @8 __miFillPolygon_internal @9 _miFillRectangles_internal @10 __miFillSppPoly @11 __miFreeStorage @12 __miInsertionSort @13 __miPolyArc_r @14 __miQuickSortSpansY @15 __miStepDash @16 __miUniquifyPaintedSet @17 __miWideDash @18 __miWideLine @19 __miZeroDash @20 __miZeroLine @21 __miZeroPolyArc_r @22 __mi_xcalloc @23 __mi_xmalloc @24 __mi_xrealloc @25 __micomputeWAET @26 __miloadAET @27 _a_begin_page @28 _a_default_plotter @29 _a_end_page @30 _a_erase_page @31 _a_initialize @32 _a_paint_path @33 _a_paint_paths @34 _a_paint_point @35 _a_paint_text_string @36 _a_set_attributes @37 _a_set_fill_color @38 _a_set_pen_color @39 _a_terminate @40 _add_arc @41 _add_arc_as_bezier3 @42 _add_arc_as_lines @43 _add_bezier2 @44 _add_bezier2_as_lines @45 _add_bezier3 @46 _add_bezier3_as_lines @47 _add_box @48 _add_box_as_lines @49 _add_circle @50 _add_circle_as_bezier3s @51 _add_circle_as_ellarcs @52 _add_circle_as_lines @53 _add_closepath @54 _add_ellarc @55 _add_ellarc_as_bezier3 @56 _add_ellarc_as_lines @57 _add_ellipse @58 _add_ellipse_as_bezier3s @59 _add_ellipse_as_ellarcs @60 _add_ellipse_as_lines @61 _add_line @62 _add_moveto @63 _ai_fill_rule @64 _alabel_hershey @65 _angle_of_arc @66 _b_begin_page @67 _b_default_plotter @68 _b_delete_image @69 _b_draw_elliptic_arc @70 _b_draw_elliptic_arc_2 @71 _b_draw_elliptic_arc_internal @72 _b_end_page @73 _b_erase_page @74 _b_initialize @75 _b_maybe_output_image @76 _b_new_image @77 _b_paint_path @78 _b_paint_paths @79 _b_paint_point @80 _b_terminate @81 _bbox_of_outbuf @82 _bbox_of_outbufs @83 _c_begin_page @84 _c_default_plotter @85 _c_end_page @86 _c_erase_page @87 _c_initialize @88 _c_paint_marker @89 _c_paint_path @90 _c_paint_paths @91 _c_paint_point @92 _c_paint_text_string @93 _c_set_attributes @94 _c_set_bg_color @95 _c_set_fill_color @96 _c_set_pen_color @97 _c_terminate @98 _cgm_cap_style @99 _cgm_emit_color_component @100 _cgm_emit_command_header @101 _cgm_emit_command_terminator @102 _cgm_emit_enum @103 _cgm_emit_index @104 _cgm_emit_integer @105 _cgm_emit_point @106 _cgm_emit_points @107 _cgm_emit_real_fixed_point @108 _cgm_emit_real_floating_point @109 _cgm_emit_string @110 _cgm_emit_unsigned_integer @111 _cgm_emit_unsigned_integer_8bit @112 _cgm_font_id_to_ps_font @113 _cgm_font_properties @114 _cgm_join_style @115 _clip_line @116 _codestring_len @117 _colornames @118 _compute_ndc_to_device_map @119 _controlify @120 _copy_params_to_plotter @121 _create_color_name_cache @122 _create_first_drawing_state @123 _default_drawstate @124 _default_plotter_params @125 _delete_color_name_cache @126 _delete_first_drawing_state @127 _delete_outbuf @128 _delete_plPath @129 _draw_hershey_glyph @130 _draw_hershey_penup_stroke @131 _draw_hershey_string @132 _draw_hershey_stroke @133 _f_begin_page @134 _f_compute_line_style @135 _f_default_plotter @136 _f_draw_arc_internal @137 _f_draw_box_internal @138 _f_draw_ellipse_internal @139 _f_end_page @140 _f_erase_page @141 _f_initialize @142 _f_paint_path @143 _f_paint_paths @144 _f_paint_point @145 _f_paint_text_string @146 _f_retrieve_font @147 _f_set_fill_color @148 _f_set_pen_color @149 _f_terminate @150 _fig_cap_style @151 _fig_color @152 _fig_join_style @153 _fig_line_style @154 _fig_stdcolors @155 _fixed_width_spacings @156 _flabelwidth_hershey @157 _flatten_path @158 _flush_plotter_outstreams @159 _free_params_in_plotter @160 _freeze_outbuf @161 _g_begin_page @162 _g_default_plotter @163 _g_end_page @164 _g_erase_page @165 _g_error @166 _g_flush_output @167 _g_get_text_width @168 _g_initialize @169 _g_maybe_prepaint_segments @170 _g_paint_marker @171 _g_paint_path @172 _g_paint_paths @173 _g_paint_point @174 _g_paint_text_string @175 _g_paint_text_string_with_escapes @176 _g_path_is_flushable @177 _g_pop_state @178 _g_push_state @179 _g_retrieve_font @180 _g_terminate @181 _g_warning @182 _get_default_plot_param @183 _get_plot_param @184 _grayscale_approx @185 _h_begin_page @186 _h_default_plotter @187 _h_end_page @188 _h_erase_page @189 _h_initialize @190 _h_maybe_switch_from_hpgl @191 _h_maybe_switch_to_hpgl @192 _h_paint_path @193 _h_paint_paths @194 _h_paint_point @195 _h_paint_text_string @196 _h_set_attributes @197 _h_set_fill_color @198 _h_set_font @199 _h_set_pen_color @200 _h_set_position @201 _h_terminate @202 _hershey_accented_char_info @203 _hershey_font_info @204 _hershey_typeface_info @205 _hpgl2_maybe_update_font @206 _hpgl_maybe_update_font @207 _hpgl_pseudocolor @208 _hpgl_shaded_pseudocolor @209 _i_begin_page @210 _i_default_plotter @211 _i_delete_image @212 _i_draw_elliptic_arc @213 _i_draw_elliptic_arc_2 @214 _i_draw_elliptic_arc_internal @215 _i_end_page @216 _i_erase_page @217 _i_initialize @218 _i_new_color_index @219 _i_new_image @220 _i_paint_path @221 _i_paint_paths @222 _i_paint_point @223 _i_scan_pixel @224 _i_set_bg_color @225 _i_set_fill_color @226 _i_set_pen_color @227 _i_start_scan @228 _i_terminate @229 _i_write_gif_header @230 _i_write_gif_image @231 _i_write_gif_trailer @232 _i_write_short_int @233 _idraw_brush_pattern @234 _idraw_stdcolornames @235 _idraw_stdcolors @236 _idraw_stdshadings @237 _kermit_bgcolor_escapes @238 _kermit_fgcolor_escapes @239 _kermit_stdcolors @240 _known_params @241 _libplot_color_to_svg_color @242 _line_styles @243 _m_begin_page @244 _m_default_plotter @245 _m_emit_float @246 _m_emit_integer @247 _m_emit_op_code @248 _m_emit_string @249 _m_emit_terminator @250 _m_end_page @251 _m_erase_page @252 _m_initialize @253 _m_maybe_prepaint_segments @254 _m_paint_marker @255 _m_paint_path @256 _m_paint_path_internal @257 _m_paint_paths @258 _m_paint_point @259 _m_paint_text_string_with_escapes @260 _m_path_is_flushable @261 _m_set_attributes @262 _m_terminate @263 _matrix_inverse @264 _matrix_norm @265 _matrix_product @266 _matrix_sing_vals @267 _maybe_output_image @268 _maybe_replace_arc @269 _maybe_switch_from_hpgl @270 _maybe_switch_to_hpgl @271 _merge_paths @272 _miAddSpansToPaintedSet @273 _miClearPaintedSet @274 _miCopyCanvas @275 _miCopyGC @276 _miCopyPaintedSetToCanvas @277 _miDeleteCanvas @278 _miDeleteEllipseCache @279 _miDeleteGC @280 _miDeletePaintedSet @281 _miDrawArcs_r @282 _miDrawLines @283 _miDrawPoints @284 _miDrawRectangles @285 _miFillArcs @286 _miFillPolygon @287 _miFillRectangles @288 _miNewCanvas @289 _miNewEllipseCache @290 _miNewGC @291 _miNewPaintedSet @292 _miSetCanvasStipple @293 _miSetCanvasTexture @294 _miSetGCAttrib @295 _miSetGCAttribs @296 _miSetGCDashes @297 _miSetGCMiterLimit @298 _miSetGCPixels @299 _miSetPixelMerge2 @300 _miSetPixelMerge3 @301 _mi_libxmi_ver @302 _n_default_plotter @303 _n_initialize @304 _n_maybe_output_image @305 _n_terminate @306 _n_write_pbm @307 _n_write_pgm @308 _n_write_pnm @309 _n_write_ppm @310 _new_outbuf @311 _new_plPath @312 _occidental_hershey_glyphs @313 _old_api_global_plotter_params @314 _oriental_hershey_glyphs @315 _p_begin_page @316 _p_compute_idraw_bgcolor @317 _p_default_plotter @318 _p_emit_common_attributes @319 _p_end_page @320 _p_erase_page @321 _p_fellipse_internal @322 _p_initialize @323 _p_paint_path @1 _p_paint_paths @325 _p_paint_point @326 _p_paint_text_string @327 _p_set_fill_color @328 _p_set_pen_color @329 _p_terminate @330 _parse_pen_string @331 _pcl_font_info @332 _pcl_typeface_info @333 _plot_xcalloc @334 _plot_xmalloc @335 _plot_xrealloc @336 _plotters @337 _plotters_len @338 _ps_cap_style @339 _ps_font_info @340 _ps_font_to_cgm_font_id @341 _ps_join_style @342 _ps_typeface_info @343 _q_default_plotter @344 _q_initialize @345 _q_maybe_switch_from_hpgl @346 _q_maybe_switch_to_hpgl @347 _q_terminate @348 _r_begin_page @349 _r_default_plotter @350 _r_end_page @351 _r_erase_page @352 _r_initialize @353 _r_maybe_prepaint_segments @354 _r_paint_path @355 _r_paint_paths @356 _r_paint_point @357 _r_path_is_flushable @358 _r_set_attributes @359 _r_set_bg_color @360 _r_set_fill_color @361 _r_set_pen_color @362 _r_terminate @363 _regis_color_chars @364 _regis_move @365 _regis_stdcolors @366 _render_non_hershey_string @367 _render_simple_string @368 _reset_outbuf @369 _reset_plPath @370 _rle_do_pixel @371 _rle_init @372 _rle_terminate @373 _s_begin_page @374 _s_default_plotter @375 _s_end_page @376 _s_erase_page @377 _s_initialize @378 _s_paint_path @379 _s_paint_paths @380 _s_paint_point @381 _s_paint_text_string @382 _s_set_matrix @383 _s_terminate @384 _set_bezier2_bbox @385 _set_bezier3_bbox @386 _set_common_mi_attributes @387 _set_ellipse_bbox @388 _set_font @389 _set_hpgl_fill_type @390 _set_hpgl_pen @391 _set_hpgl_pen_type @392 _set_line_end_bbox @393 _set_line_join_bbox @394 _set_page_type @395 _setplparam @396 _stick_font_info @397 _stick_kerning_tables @398 _stick_spacing_tables @399 _stick_typeface_info @400 _string_to_color @401 _svg_colornames @402 _t_begin_page @403 _t_default_plotter @404 _t_end_page @405 _t_erase_page @406 _t_initialize @407 _t_maybe_prepaint_segments @408 _t_paint_point @409 _t_path_is_flushable @410 _t_set_attributes @411 _t_set_bg_color @412 _t_set_pen_color @413 _t_terminate @414 _tek_mode @415 _tek_move @416 _tek_vector @417 _tek_vector_compressed @418 _truecenter @419 _update_bbox @420 _update_buffer @421 _update_buffer_by_added_bytes @422 _variable_width_katakana_spacings @423 _variable_width_spacings @424 _vscale @425 _write_byte @426 _write_bytes @427 _write_string @428 _xatan2 @429 _z_default_plotter @430 _z_initialize @431 _z_maybe_output_image @432 _z_terminate @433 libplot_error_handler @434 libplot_warning_handler @435 pl_alabel @436 pl_alabel_r @437 pl_arc @438 pl_arc_r @439 pl_arcrel @440 pl_arcrel_r @441 pl_bezier2 @442 pl_bezier2_r @443 pl_bezier2rel @444 pl_bezier2rel_r @445 pl_bezier3 @446 pl_bezier3_r @447 pl_bezier3rel @448 pl_bezier3rel_r @449 pl_bgcolor @450 pl_bgcolor_r @451 pl_bgcolorname @452 pl_bgcolorname_r @453 pl_box @454 pl_box_r @455 pl_boxrel @456 pl_boxrel_r @457 pl_capmod @458 pl_capmod_r @459 pl_circle @460 pl_circle_r @461 pl_circlerel @462 pl_circlerel_r @463 pl_closepath @464 pl_closepath_r @465 pl_closepl @466 pl_closepl_r @467 pl_color @468 pl_color_r @469 pl_colorname @470 pl_colorname_r @471 pl_cont @472 pl_cont_r @473 pl_contrel @474 pl_contrel_r @475 pl_copyplparams @476 pl_deletepl @477 pl_deletepl_r @478 pl_deleteplparams @479 pl_ellarc @480 pl_ellarc_r @481 pl_ellarcrel @482 pl_ellarcrel_r @483 pl_ellipse @484 pl_ellipse_r @485 pl_ellipserel @486 pl_ellipserel_r @487 pl_endpath @488 pl_endpath_r @489 pl_endsubpath @490 pl_endsubpath_r @491 pl_erase @492 pl_erase_r @493 pl_farc @494 pl_farc_r @495 pl_farcrel @496 pl_farcrel_r @497 pl_fbezier2 @498 pl_fbezier2_r @499 pl_fbezier2rel @500 pl_fbezier2rel_r @501 pl_fbezier3 @502 pl_fbezier3_r @503 pl_fbezier3rel @504 pl_fbezier3rel_r @505 pl_fbox @506 pl_fbox_r @507 pl_fboxrel @508 pl_fboxrel_r @509 pl_fcircle @510 pl_fcircle_r @511 pl_fcirclerel @512 pl_fcirclerel_r @513 pl_fconcat @514 pl_fconcat_r @515 pl_fcont @516 pl_fcont_r @517 pl_fcontrel @518 pl_fcontrel_r @519 pl_fellarc @520 pl_fellarc_r @521 pl_fellarcrel @522 pl_fellarcrel_r @523 pl_fellipse @524 pl_fellipse_r @525 pl_fellipserel @526 pl_fellipserel_r @527 pl_ffontname @528 pl_ffontname_r @529 pl_ffontsize @530 pl_ffontsize_r @531 pl_fillcolor @532 pl_fillcolor_r @533 pl_fillcolorname @534 pl_fillcolorname_r @535 pl_fillmod @536 pl_fillmod_r @537 pl_filltype @538 pl_filltype_r @539 pl_flabelwidth @540 pl_flabelwidth_r @541 pl_fline @542 pl_fline_r @543 pl_flinedash @544 pl_flinedash_r @545 pl_flinerel @546 pl_flinerel_r @547 pl_flinewidth @548 pl_flinewidth_r @549 pl_flushpl @550 pl_flushpl_r @551 pl_fmarker @552 pl_fmarker_r @553 pl_fmarkerrel @554 pl_fmarkerrel_r @555 pl_fmiterlimit @556 pl_fmiterlimit_r @557 pl_fmove @558 pl_fmove_r @559 pl_fmoverel @560 pl_fmoverel_r @561 pl_fontname @562 pl_fontname_r @563 pl_fontsize @564 pl_fontsize_r @565 pl_fpoint @566 pl_fpoint_r @567 pl_fpointrel @568 pl_fpointrel_r @569 pl_frotate @570 pl_frotate_r @571 pl_fscale @572 pl_fscale_r @573 pl_fsetmatrix @574 pl_fsetmatrix_r @575 pl_fspace @576 pl_fspace2 @577 pl_fspace2_r @578 pl_fspace_r @579 pl_ftextangle @580 pl_ftextangle_r @581 pl_ftranslate @582 pl_ftranslate_r @583 pl_get_hershey_font_info @584 pl_get_pcl_font_info @585 pl_get_ps_font_info @586 pl_get_stick_font_info @587 pl_havecap @588 pl_havecap_r @589 pl_joinmod @590 pl_joinmod_r @591 pl_label @592 pl_label_r @593 pl_labelwidth @594 pl_labelwidth_r @595 pl_libplot_ver @596 pl_line @597 pl_line_r @598 pl_linedash @599 pl_linedash_r @600 pl_linemod @601 pl_linemod_r @602 pl_linerel @603 pl_linerel_r @604 pl_linewidth @605 pl_linewidth_r @606 pl_marker @607 pl_marker_r @608 pl_markerrel @609 pl_markerrel_r @610 pl_move @611 pl_move_r @612 pl_moverel @613 pl_moverel_r @614 pl_newpl @615 pl_newpl_r @616 pl_newplparams @617 pl_openpl @618 pl_openpl_r @619 pl_orientation @620 pl_orientation_r @621 pl_outfile @622 pl_outfile_r @623 pl_parampl @624 pl_pencolor @625 pl_pencolor_r @626 pl_pencolorname @627 pl_pencolorname_r @628 pl_pentype @629 pl_pentype_r @630 pl_point @631 pl_point_r @632 pl_pointrel @633 pl_pointrel_r @634 pl_restorestate @635 pl_restorestate_r @636 pl_savestate @637 pl_savestate_r @638 pl_selectpl @639 pl_setplparam @640 pl_space @641 pl_space2 @642 pl_space2_r @643 pl_space_r @644 pl_textangle @645 pl_textangle_r @646 ; end of file python2-biggles-1.6.6/python-biggles.spec0000644000175100017510000000574311357715757017421 0ustar noltanolta# # $Id: python-biggles.spec,v 1.28 2010/04/09 21:28:15 mrnolta Exp $ # # Copyright (C) 2001 Mike Nolta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # Version: 1.6.6 Release: 1 Name: python-biggles Summary: high-level scientific plotting module for Python Packager: Michael Nolta Source: http://download.sourceforge.net/biggles/python-biggles-%{version}.tar.gz URL: http://biggles.sourceforge.net/ Copyright: GPL Group: Applications/Graphics Requires: plotutils Requires: python BuildRoot: /var/tmp/%{name}-%{version}-buildroot Prefix: /usr %define pythonversion %(python -V 2>&1 | cut -c8-10) %define bigglesdir %{prefix}/lib/python%{pythonversion}/site-packages/biggles %description Biggles is a Python module for creating publication-quality 2D scientific plots. It supports multiple output formats (postscript, x11, png, svg, gif), understands simple TeX, and sports a high-level, elegant interface. It's intended for technical users with sophisticated plotting needs. %prep %setup -q %build make %install rm -rf %{buildroot} mkdir -p %{buildroot}%{bigglesdir} install -m644 src/config.ini %{buildroot}%{bigglesdir}/config.ini install -m644 src/*.py %{buildroot}%{bigglesdir}/ install -m644 src/*.pyc %{buildroot}%{bigglesdir}/ install -m755 src/*.so %{buildroot}%{bigglesdir}/ mkdir -p %{buildroot}%{bigglesdir}/libplot install -m644 src/libplot/*.py %{buildroot}%{bigglesdir}/libplot install -m644 src/libplot/*.pyc %{buildroot}%{bigglesdir}/libplot install -m755 src/libplot/*.so %{buildroot}%{bigglesdir}/libplot %files %defattr(-,root,root) %doc COPYING CREDITS ChangeLog README examples %dir %{bigglesdir} %config %{bigglesdir}/config.ini %{bigglesdir}/*.py %{bigglesdir}/*.pyc %{bigglesdir}/*.so %dir %{bigglesdir}/libplot %{bigglesdir}/libplot/*.py %{bigglesdir}/libplot/*.pyc %{bigglesdir}/libplot/*.so %changelog * Sat Nov 03 2001 Michael Nolta - Removed *.pyo files. Made code slower. * Fri Oct 26 2001 Michael Nolta - Updated for new file layout. Added *.pyo files. * Sun Jan 25 2001 Michael Nolta - Added support for *.so files. * Sun Dec 17 2000 Michael Nolta - Added *.pyc files. * Tue Nov 24 2000 Michael Nolta - Created.