2525 x,y = np.ogrid[-10:11,-10:11]
2626 gp.plot( x**2 + y**2,
2727 title = 'Heat map',
28+ unset = 'grid',
2829 cmds = 'set view map',
2930 _with = 'image',
3031 tuplesize = 3)
4849is described in great detail at its upstream website: http://www.gnuplot.info
4950
5051gnuplotlib has an object-oriented interface (via class gnuplotlib) and a few
51- helper class-less functions (plot() and plot3d()) . Each instance of class
52- gnuplotlib has a gnuplot process associated with it, which has (usually) a plot
53- window to go with it. If multiple simultaneous plot windows are desired, create
54- a separate class gnuplotlib object for each.
52+ helper class-less functions (plot(), plot3d(), plotimage()) . Each instance of
53+ class gnuplotlib has a gnuplot process associated with it, which has (usually) a
54+ plot window to go with it. If multiple simultaneous plot windows are desired,
55+ create a separate class gnuplotlib object for each.
5556
5657The helper functions reuse a single global gnuplotlib instance, so each such
5758invocation rewrites over the previous gnuplot window.
7475#+END_SRC
7576
7677plot3d(...) simply calls plot(...) with an extra plot option _3d=True.
78+ plotimage(...) simply calls plot(...) with extra plot options _with='image',
79+ tuplesize=3.
7780
7881If just a single curve is plotted, 'curve' can simply be a sequence of numpy
7982arrays representing coordinates of each point. For instance:
133136When a particular tuplesize is specified, gnuplotlib will attempt to read that
134137many arrays. If there aren't enough arrays available, gnuplotlib will throw an
135138error, unless an implicit domain can be used. This happens if we are EXACTLY 1
136- or 2 arrayss short (usually when making 2D and 3D plots respectively).
139+ or 2 arrays short (usually when making 2D and 3D plots respectively).
137140
138141When making a simple 2D plot, if exactly 1 dimension is missing, gnuplotlib will
139142use numpy.arange(N) as the domain. This is why code like
142145 plot(numpy.array([1,5,3,4,4]))
143146#+END_SRC
144147
145- works. Only one array is given here, but a default tuplesize of 2 is active , and
146- we are thus exactly 1 array short. This is thus equivalent to
148+ works. Only one array is given here, but the default tuplesize is 2 , and we are
149+ thus exactly 1 array short. This is thus equivalent to
147150
148151#+BEGIN_SRC python
149152 plot(numpy.arange(5), numpy.array([1,5,3,4,4]) )
154157
155158#+BEGIN_SRC python
156159 xy = numpy.arange(21*21).reshape(21*21)
157- plot3d ( xy, _with = 'points')
160+ plot ( xy, _with = 'points', _3d=True )
158161#+END_SRC
159162
160163Here the only given array has dimensions (21,21). This is a 3D plot, so we are
170173 x,y = np.ogrid[-10:11,-10:11]
171174 gp.plot( x**2 + y**2,
172175 title = 'Heat map',
173- cmds = 'set view map',
176+ set = 'view map',
174177 _with = 'image',
175178 tuplesize = 3)
176179#+END_SRC
251254
252255If given, these set the extents of the plot window for the requested axes.
253256Either min/max or range can be given but not both. min/max are numerical values.
254- '*range' is a string 'min:max' with either one allowed to be omitted. '*inv' is
255- a boolean that reverses this axis. If the bounds are known, this can also be
256- accomplished by setting max < min.
257+ '*range' is a string 'min:max' with either one allowed to be omitted; it can
258+ also be a [min,max] tuple or list. '*inv' is a boolean that reverses this axis.
259+ If the bounds are known, this can also be accomplished by setting max < min.
257260
258261The y2 axis is the secondary y-axis that is enabled by the 'y2' curve option.
259262The 'cb' axis represents the color axis, used when color-coded plots are being
434437
435438Generates 3D plots. Shorthand for 'plot(..., _3d=True)'
436439
440+ ** global plotimage(...)
441+
442+ Generates an image plot. Shorthand for 'plot(..., _with='image', tuplesize=3)'
443+
437444
438445* RECIPES
439446
569576 x,y = np.ogrid[-10:11,-10:11]
570577 gp.plot( x**2 + y**2,
571578 title = 'Heat map',
572- cmds = 'set view map',
579+ set = 'view map',
573580 _with = 'image',
574581 tuplesize = 3)
575582#+END_SRC
@@ -849,12 +856,17 @@ def active(opt): return self._activePlotOption(opt)
849856 if len (self .plotOptions [axis + 'min' ] + self .plotOptions [axis + 'max' ]):
850857 rangeopt_val = ':' .join ((self .plotOptions [axis + 'min' ], self .plotOptions [axis + 'max' ]))
851858 elif have (rangeopt_name ):
859+ # A range was given. If it's a string, just take it. It can also
860+ # be a two-value list for the min/max
852861 rangeopt_val = self .plotOptions [rangeopt_name ]
862+ if isinstance (rangeopt_val , (list , tuple )):
863+ rangeopt_val = ':' .join (str (x ) for x in rangeopt_val )
853864 else :
854865 rangeopt_val = ''
855- cmds .append ( "set {} [{}] {}" .format (rangeopt_name ,
856- rangeopt_val ,
857- 'reverse' if active (axis + 'inv' ) else '' ))
866+
867+ cmds .append ( "set {} [{}] {}" .format (rangeopt_name ,
868+ rangeopt_val ,
869+ 'reverse' if active (axis + 'inv' ) else '' ))
858870
859871 # set the curve labels
860872 if not axis == 'cb' :
@@ -1566,9 +1578,11 @@ class gnuplotlib provides full power and flexibility, but for simple plots this
15661578 raise GnuplotlibError ("Option '{}' not a known curve or plot option" .format (opt ))
15671579
15681580 # I make a brand new gnuplot process if necessary. If one already exists, I
1569- # re-initialize it
1581+ # re-initialize it. If we're doing a data dump then I also create a new
1582+ # object. There's no gnuplot session to reuse in that case, and otherwise
1583+ # the dumping won't get activated
15701584 global globalplot
1571- if not globalplot :
1585+ if not globalplot or _active ( 'dump' , plotOptions ) :
15721586 globalplot = gnuplotlib (** plotOptions )
15731587 else :
15741588 globalplot .__init__ (** plotOptions )
@@ -1605,6 +1619,33 @@ class gnuplotlib provides full power and flexibility, but for simple 3d plots
16051619
16061620
16071621
1622+ def plotimage (* curves , ** jointOptions ):
1623+
1624+ r'''A simple wrapper around class gnuplotlib to plot image maps
1625+
1626+ SYNOPSIS
1627+
1628+ import numpy as np
1629+ import gnuplotlib as gp
1630+
1631+ x,y = np.ogrid[-10:11,-10:11]
1632+ gp.plotimage( x**2 + y**2,
1633+ title = 'Heat map')
1634+
1635+ DESCRIPTION
1636+
1637+ class gnuplotlib provides full power and flexibility, but for simple image-map
1638+ plots this wrapper is easier to use. plotimage() simply calls plot(...,
1639+ _with='image', tuplesize=3). See the documentation for plot() and class
1640+ gnuplotlib for full details.
1641+
1642+ '''
1643+ jointOptions ['_with' ] = 'image'
1644+ jointOptions ['tuplesize' ] = 3
1645+ plot (* curves , ** jointOptions )
1646+
1647+
1648+
16081649
16091650
16101651
@@ -1631,7 +1672,7 @@ class gnuplotlib provides full power and flexibility, but for simple 3d plots
16311672 x ,y = np .ogrid [- 10 :11 ,- 10 :11 ]
16321673 gp .plot ( x ** 2 + y ** 2 ,
16331674 title = 'Heat map' ,
1634- cmds = 'set view map' ,
1675+ set = 'view map' ,
16351676 _with = 'image' ,
16361677 tuplesize = 3 )
16371678 time .sleep (5 )
0 commit comments