Hi, The matplotlib.collections.Collection documentation reads: "All
properties in a collection must be sequences or scalars; if scalars,
they will be converted to sequences. The property of the ith element
of the collection is: prop[i % len(props)]". I had a look at the
docstring documentation from ipython, but I didn't find out how the
above is achieved (I am learning Python together with numpy,
matplotlib, etc.). In my own code, how could I do something like
this? If you point to a relevant location on the source code, that's
import matplotlib.cbook as cbook
def to_sequence(arg):
if cbook.is_iterable(arg):
return arg
return [arg]
Above is an example of how one can turn a scalar into a sequence (a list, in this case) if necessary.
alright. I also get confused sometimes because of the multiple (and
sometimes interchangeable) ways of specifying arguments: sequences
(list, tuples), numpy arrays, etc. I started using almost exclusively
numpy arrays (probably due to my matlab background), but I am
starting to mix a bit of everything now (depending on what "sources
of inspiration" I use), so I wondered what a good guideline would be.
Different types of sequence have different advantages and disadvantages. Tuples are immutable. Lists are much more flexible, and can be extended. ndarrays are fixed-size, but facilitate efficient computation.
If a function or method accepts any kind of sequence for a given argument, then probably the thing to do is give it whatever you have already, or whatever is most convenient to generate. Lists are a good default if the sequence has only a few elements and you are writing them out, rather than calculating them from some other sequence. In other words, if a function is flexible, then trust the function to do whatever conversions it needs internally; there is no particular advantage in doing the conversion yourself when you specify the argument.
Eric
···
jorgesmbox-ml@...1664... wrote: