Skip to content

Commit 7d83ae3

Browse files
committed
Merge branch 'master' into debian
2 parents 4839681 + e90504a commit 7d83ae3

3 files changed

Lines changed: 81 additions & 33 deletions

File tree

README.org

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ gnuplotlib: a gnuplot-based plotting backend for numpy
2222
x,y = np.ogrid[-10:11,-10:11]
2323
gp.plot( x**2 + y**2,
2424
title = 'Heat map',
25+
unset = 'grid',
2526
cmds = 'set view map',
2627
_with = 'image',
2728
tuplesize = 3)
@@ -45,10 +46,10 @@ making available the full power and flexibility of the Gnuplot backend. Gnuplot
4546
is described in great detail at its upstream website: http://www.gnuplot.info
4647

4748
gnuplotlib has an object-oriented interface (via class gnuplotlib) and a few
48-
helper class-less functions (plot() and plot3d()). Each instance of class
49-
gnuplotlib has a gnuplot process associated with it, which has (usually) a plot
50-
window to go with it. If multiple simultaneous plot windows are desired, create
51-
a separate class gnuplotlib object for each.
49+
helper class-less functions (plot(), plot3d(), plotimage()). Each instance of
50+
class gnuplotlib has a gnuplot process associated with it, which has (usually) a
51+
plot window to go with it. If multiple simultaneous plot windows are desired,
52+
create a separate class gnuplotlib object for each.
5253

5354
The helper functions reuse a single global gnuplotlib instance, so each such
5455
invocation rewrites over the previous gnuplot window.
@@ -71,6 +72,8 @@ A call to plot(...) is simpler:
7172
#+END_SRC
7273

7374
plot3d(...) simply calls plot(...) with an extra plot option _3d=True.
75+
plotimage(...) simply calls plot(...) with extra plot options _with='image',
76+
tuplesize=3.
7477

7578
If just a single curve is plotted, 'curve' can simply be a sequence of numpy
7679
arrays representing coordinates of each point. For instance:
@@ -130,7 +133,7 @@ yet (numpy is missing thread_define from PDL)
130133
When a particular tuplesize is specified, gnuplotlib will attempt to read that
131134
many arrays. If there aren't enough arrays available, gnuplotlib will throw an
132135
error, unless an implicit domain can be used. This happens if we are EXACTLY 1
133-
or 2 arrayss short (usually when making 2D and 3D plots respectively).
136+
or 2 arrays short (usually when making 2D and 3D plots respectively).
134137

135138
When making a simple 2D plot, if exactly 1 dimension is missing, gnuplotlib will
136139
use numpy.arange(N) as the domain. This is why code like
@@ -139,8 +142,8 @@ use numpy.arange(N) as the domain. This is why code like
139142
plot(numpy.array([1,5,3,4,4]))
140143
#+END_SRC
141144

142-
works. Only one array is given here, but a default tuplesize of 2 is active, and
143-
we are thus exactly 1 array short. This is thus equivalent to
145+
works. Only one array is given here, but the default tuplesize is 2, and we are
146+
thus exactly 1 array short. This is thus equivalent to
144147

145148
#+BEGIN_SRC python
146149
plot(numpy.arange(5), numpy.array([1,5,3,4,4]) )
@@ -151,7 +154,7 @@ short. In this case, gnuplotlib will use a 2D grid as a domain. Example:
151154

152155
#+BEGIN_SRC python
153156
xy = numpy.arange(21*21).reshape(21*21)
154-
plot3d( xy, _with = 'points')
157+
plot( xy, _with = 'points', _3d=True)
155158
#+END_SRC
156159

157160
Here the only given array has dimensions (21,21). This is a 3D plot, so we are
@@ -167,7 +170,7 @@ one can be plotting a color map:
167170
x,y = np.ogrid[-10:11,-10:11]
168171
gp.plot( x**2 + y**2,
169172
title = 'Heat map',
170-
cmds = 'set view map',
173+
set = 'view map',
171174
_with = 'image',
172175
tuplesize = 3)
173176
#+END_SRC
@@ -248,9 +251,9 @@ requires Gnuplot >= 4.4
248251

249252
If given, these set the extents of the plot window for the requested axes.
250253
Either min/max or range can be given but not both. min/max are numerical values.
251-
'*range' is a string 'min:max' with either one allowed to be omitted. '*inv' is
252-
a boolean that reverses this axis. If the bounds are known, this can also be
253-
accomplished by setting max < min.
254+
'*range' is a string 'min:max' with either one allowed to be omitted; it can
255+
also be a [min,max] tuple or list. '*inv' is a boolean that reverses this axis.
256+
If the bounds are known, this can also be accomplished by setting max < min.
254257

255258
The y2 axis is the secondary y-axis that is enabled by the 'y2' curve option.
256259
The 'cb' axis represents the color axis, used when color-coded plots are being
@@ -431,6 +434,10 @@ Each 'plot()' call reuses the same window.
431434

432435
Generates 3D plots. Shorthand for 'plot(..., _3d=True)'
433436

437+
** global plotimage(...)
438+
439+
Generates an image plot. Shorthand for 'plot(..., _with='image', tuplesize=3)'
440+
434441

435442
* RECIPES
436443

@@ -566,7 +573,7 @@ Image arrays plots can be plotted as a heat map:
566573
x,y = np.ogrid[-10:11,-10:11]
567574
gp.plot( x**2 + y**2,
568575
title = 'Heat map',
569-
cmds = 'set view map',
576+
set = 'view map',
570577
_with = 'image',
571578
tuplesize = 3)
572579
#+END_SRC

gnuplotlib.py

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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)
@@ -48,10 +49,10 @@
4849
is described in great detail at its upstream website: http://www.gnuplot.info
4950
5051
gnuplotlib 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
5657
The helper functions reuse a single global gnuplotlib instance, so each such
5758
invocation rewrites over the previous gnuplot window.
@@ -74,6 +75,8 @@
7475
#+END_SRC
7576
7677
plot3d(...) 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
7881
If just a single curve is plotted, 'curve' can simply be a sequence of numpy
7982
arrays representing coordinates of each point. For instance:
@@ -133,7 +136,7 @@
133136
When a particular tuplesize is specified, gnuplotlib will attempt to read that
134137
many arrays. If there aren't enough arrays available, gnuplotlib will throw an
135138
error, 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
138141
When making a simple 2D plot, if exactly 1 dimension is missing, gnuplotlib will
139142
use numpy.arange(N) as the domain. This is why code like
@@ -142,8 +145,8 @@
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]) )
@@ -154,7 +157,7 @@
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
160163
Here the only given array has dimensions (21,21). This is a 3D plot, so we are
@@ -170,7 +173,7 @@
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
@@ -251,9 +254,9 @@
251254
252255
If given, these set the extents of the plot window for the requested axes.
253256
Either 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
258261
The y2 axis is the secondary y-axis that is enabled by the 'y2' curve option.
259262
The 'cb' axis represents the color axis, used when color-coded plots are being
@@ -434,6 +437,10 @@
434437
435438
Generates 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
@@ -569,7 +576,7 @@
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)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def run(self):
1414

1515

1616
setup(name = 'gnuplotlib',
17-
version = '0.4',
17+
version = '0.6',
1818
author = 'Dima Kogan',
1919
author_email = 'dima@secretsauce.net',
2020
url = 'http://github.com/dkogan/gnuplotlib',

0 commit comments

Comments
 (0)