Skip to content

Commit 8a4aa27

Browse files
committed
Added "axes" curve option
This is a more general "y2" option, and is exclusive with it. "y2=True" is equivalent to "axes 'x1y2'". But you can also ask for "axes 'x2y2'", which you couldn't do before
1 parent 7efbc45 commit 8a4aa27

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

README.org

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,17 @@ documentation for the 'with' keyword for more information
923923
Identical to 'with'. In python 'with' is a reserved word so it is illegal to use
924924
it as a keyword arg key, so '_with' exists as an alias
925925

926+
- axes
927+
928+
One of: ('x1y1','x1y2','x2y1','x2y2'). Specifies which xy axes in the plot
929+
should define this curve. This is the left/right and up/down axes in the plot.
930+
Only applies to 2D plots. Exclusive with the "y2" option
931+
926932
- y2
927933

928-
If true, requests that this curve be plotted on the y2 axis instead of the main y axis
934+
If true, requests that this curve be plotted on the x1y2 axes instead of the
935+
default x1y1 axes. This is a special case of the "axes" option, and is exclusive
936+
with it
929937

930938
- tuplesize
931939

gnuplotlib.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,17 @@ class gnuplotlib has a separate gnuplot process and a plot window. If multiple
841841
Identical to 'with'. In python 'with' is a reserved word so it is illegal to use
842842
it as a keyword arg key, so '_with' exists as an alias
843843
844+
- axes
845+
846+
One of: ('x1y1','x1y2','x2y1','x2y2'). Specifies which xy axes in the plot
847+
should define this curve. This is the left/right and up/down axes in the plot.
848+
Only applies to 2D plots. Exclusive with the "y2" option
849+
844850
- y2
845851
846-
If true, requests that this curve be plotted on the y2 axis instead of the main y axis
852+
If true, requests that this curve be plotted on the x1y2 axes instead of the
853+
default x1y1 axes. This is a special case of the "axes" option, and is exclusive
854+
with it
847855
848856
- tuplesize
849857
@@ -1148,11 +1156,14 @@ class gnuplotlib has a separate gnuplot process and a plot window. If multiple
11481156
'cbmax', 'cbmin', 'cbrange', 'cblabel'))
11491157

11501158
knownCurveOptions = frozenset(( 'with', # both a plot option and a curve option
1151-
'legend', 'y2', 'tuplesize', 'using',
1159+
'legend', 'axes', 'y2', 'tuplesize', 'using',
11521160
'histogram', 'binwidth'))
11531161

11541162
knownInteractiveTerminals = frozenset(('x11', 'wxt', 'qt', 'aquaterm'))
11551163

1164+
knownAxes = frozenset(('x1y1','x1y2','x2y1','x2y2'))
1165+
1166+
11561167
keysAcceptingIterable = frozenset(('cmds','set','unset','equation','equation_below','equation_above'))
11571168

11581169
# when testing plots with ASCII i/o, this is the unit of test data
@@ -1988,8 +1999,11 @@ def optioncmd(curve):
19881999
# back on the global
19892000
_with = curve['with'] if 'with' in curve else subplotOptions['with']
19902001

1991-
if _with: cmd += "with {} ".format(_with)
1992-
if curve.get('y2'): cmd += "axes x1y2 "
2002+
if _with: cmd += "with {} ".format(_with)
2003+
2004+
axes = curve.get('axes')
2005+
if axes is not None:
2006+
cmd += f"axes {axes} "
19932007

19942008
return cmd
19952009

@@ -2044,10 +2058,10 @@ def getTestDataLen(curve):
20442058
basecmd = ''
20452059

20462060
# if anything is to be plotted on the y2 axis, set it up
2047-
if any( curve.get('y2') for curve in curves ):
2048-
if subplotOptions.get('3d'):
2049-
raise GnuplotlibError("3d plots don't have a y2 axis")
2050-
2061+
if subplotOptions.get('3d') and \
2062+
any( 'axes' in curve for curve in curves ):
2063+
raise GnuplotlibError("3d plots cannot have 'axes' specified")
2064+
if any( curve.get('axes','x')[-1] == '2' for curve in curves ):
20512065
basecmd += "set ytics nomirror\n"
20522066
basecmd += "set y2tics\n"
20532067

@@ -2229,6 +2243,17 @@ def reformat(curve):
22292243
if not opt in knownCurveOptions:
22302244
raise GnuplotlibError("'{}' not a known curve option".format(opt))
22312245

2246+
axes = curve.get('axes')
2247+
if axes is not None:
2248+
if not axes in knownAxes:
2249+
raise GnuplotlibError(f'"axes" must be one of {knownAxes}, but got {axes=}')
2250+
if curve.get('y2'):
2251+
if axes is not None:
2252+
raise GnuplotlibError('"y2" and "axes" are mutually exclusive')
2253+
del curve['y2']
2254+
curve['axes'] = 'x1y2'
2255+
2256+
22322257
# tuplesize is either given explicitly, or taken from the '3d' plot
22332258
# option. 2d plots default to tuplesize=2 and 3d plots to
22342259
# tuplesize=3. This means that the tuplesize can be omitted for

0 commit comments

Comments
 (0)