Skip to content

Commit 5f2d163

Browse files
committed
add_plot_option() takes multiple values in a list
This is a bit uglier, but it has exactly the same semantics as the plot options that can take multiple values. I can now gp.add_plot_option(opts0, 'set', opts1['set']) Previously I would need to do either that or gp.add_plot_option(opts0, 'set', *opts1['set']) depending on what was actually in opts1['set']. THIS IS AN API BREAK. But this feature is less than one week old, so I think it's ok. Nobody is using it
1 parent 1cd5cae commit 5f2d163

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

gnuplotlib.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,12 +1200,7 @@ def _normalize_options_dict(d):
12001200

12011201
d2 = {}
12021202
for key in d:
1203-
key_normalized = key if key[0] != '_' else key[1:]
1204-
if key_normalized in keysAcceptingIterable and \
1205-
isinstance(d[key], (list,tuple)):
1206-
add_plot_option(d2, key, *d[key])
1207-
else:
1208-
add_plot_option(d2, key, d[key])
1203+
add_plot_option(d2, key, d[key])
12091204
return d2
12101205

12111206
class GnuplotlibError(Exception):
@@ -2750,7 +2745,7 @@ def wait():
27502745
globalplot.wait()
27512746

27522747

2753-
def add_plot_option(d, key, *values):
2748+
def add_plot_option(d, key, values):
27542749
r'''Ingests new key/value pairs into an option dict
27552750
27562751
SYNOPSIS
@@ -2784,15 +2779,19 @@ def add_plot_option(d, key, *values):
27842779
keys support multiple values. If a duplicate is given, it will either raise
27852780
an exception, or append to the existing list, as appropriate.
27862781
2787-
Multiple values can be given in one call.
2782+
If the given key supports multiple values, they can be given in a single
2783+
call, as a list or a tuple.
27882784
27892785
'''
27902786

2787+
key_normalized = key if key[0] != '_' else key[1:]
2788+
if not (key_normalized in keysAcceptingIterable and \
2789+
isinstance(values, (list,tuple))):
2790+
values = (values,)
2791+
27912792
values = [v for v in values if v is not None]
27922793
if len(values) == 0: return
27932794

2794-
key_normalized = key if key[0] != '_' else key[1:]
2795-
27962795
if key_normalized not in keysAcceptingIterable:
27972796
if key in d or key_normalized in d or len(values) > 1:
27982797
# Already have old key, so can't add a new key. Or have multiple new

0 commit comments

Comments
 (0)