Skip to content

Commit 3ff0ebc

Browse files
committed
Added add_plot_option()
1 parent 003415c commit 3ff0ebc

File tree

3 files changed

+172
-76
lines changed

3 files changed

+172
-76
lines changed

README.org

+53-15
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,8 @@ process calling gnuplotlib.
690690

691691
- set/unset
692692

693-
These take either a string or a list. If given a string, a set or unset gnuplot
694-
command is executed with that argument. If given a list, elements of that list
695-
are set/unset separately. Example:
693+
Either a string or a list/tuple; if given a list/tuple, each element is used in
694+
separate set/unset command. Example:
696695

697696
#+BEGIN_SRC python
698697
plot(..., set='grid', unset=['xtics', 'ytics])
@@ -704,9 +703,9 @@ instead of the normal behavior of a subplot option overriding the process option
704703

705704
- cmds
706705

707-
Arbitrary extra commands to pass to gnuplot before the plots are created. These
708-
are passed directly to gnuplot, without any validation. The value is either a
709-
string or a list of strings, one per command
706+
Either a string or a list/tuple; if given a list/tuple, each element is used in
707+
separate command. Arbitrary extra commands to pass to gnuplot before the plots
708+
are created. These are passed directly to gnuplot, without any validation.
710709

711710
This is both a process and a subplot option. If both are given, BOTH are used,
712711
instead of the normal behavior of a subplot option overriding the process option
@@ -775,9 +774,8 @@ so '_3d' is accepted for that purpose. Same issue exists with with/_with
775774

776775
- set/unset
777776

778-
These take either a string or a list. If given a string, a set or unset gnuplot
779-
command is executed with that argument. If given a list, elements of that list
780-
are set/unset separately. Example:
777+
Either a string or a list/tuple; if given a list/tuple, each element is used in
778+
separate set/unset command. Example:
781779

782780
#+BEGIN_SRC python
783781
plot(..., set='grid', unset=['xtics', 'ytics])
@@ -789,9 +787,9 @@ instead of the normal behavior of a subplot option overriding the process option
789787

790788
- cmds
791789

792-
Arbitrary extra commands to pass to gnuplot before the plots are created. These
793-
are passed directly to gnuplot, without any validation. The value is either a
794-
string or a list of strings, one per command
790+
Either a string or a list/tuple; if given a list/tuple, each element is used in
791+
separate command. Arbitrary extra commands to pass to gnuplot before the plots
792+
are created. These are passed directly to gnuplot, without any validation.
795793

796794
This is both a process and a subplot option. If both are given, BOTH are used,
797795
instead of the normal behavior of a subplot option overriding the process option
@@ -847,9 +845,9 @@ options), then it is up to the user to flip the axis, if that's what they want.
847845

848846
- equation, equation_above, equation_below
849847

850-
These options allows equations represented as formula strings to be plotted
851-
along with data passed in as numpy arrays. These can be a string (for a single
852-
equation) or an array/tuple of strings (for multiple equations). See the
848+
Either a string or a list/tuple; if given a list/tuple, each element is used in
849+
separate equation to plot. These options allows equations represented as formula
850+
strings to be plotted along with data passed in as numpy arrays. See the
853851
"Symbolic equations" section above.
854852

855853
By default, the equations are plotted BEFORE other data, so the data plotted
@@ -1335,6 +1333,46 @@ This applies to the global gnuplotlib object.
13351333
It's not at all trivial to detect if a current plot window exists. If not,
13361334
this function will end up waiting forever, and the user will need to Ctrl-C
13371335

1336+
** add_plot_option()
1337+
Ingests new key/value pairs into an option dict
1338+
1339+
SYNOPSIS
1340+
1341+
#+BEGIN_SRC python
1342+
# A baseline plot_options dict was given to us. We want to make the
1343+
# plot, but make sure to omit the legend key
1344+
1345+
add_plot_option(plot_options, 'unset', 'key')
1346+
1347+
gp.plot(..., **plot_options)
1348+
#+END_SRC
1349+
1350+
DESCRIPTION
1351+
1352+
Given a plot_options dict we can easily add a new option with
1353+
1354+
#+BEGIN_SRC python
1355+
plot_options[key] = value
1356+
#+END_SRC
1357+
1358+
This has several potential problems:
1359+
1360+
- If an option for this key already exists, the above will overwrite the old
1361+
value instead of adding a NEW option
1362+
1363+
- All options may take a leading _ to avoid conflicting with Python reserved
1364+
words (set, _set for instance). The above may unwittingly create a
1365+
duplicate
1366+
1367+
- Some plot options support multiple values, which the simple call ignores
1368+
completely
1369+
1370+
THIS function takes care of the _ in keys. And this function knows which
1371+
keys support multiple values. If a duplicate is given, it will either raise
1372+
an exception, or append to the existing list, as appropriate.
1373+
1374+
Multiple values can be given in one call.
1375+
13381376
* COMPATIBILITY
13391377

13401378
Python 2 and Python 3 should both be supported. Please report a bug if either

0 commit comments

Comments
 (0)