Several patches: kwargs cleanup, legend-kwargs, legend-fontsize

Ouch, sorry, I do not even have 2.2 installed. Guess with

    > that information, the whole patch becomes bogus.

    > On the other hand: simpy reverting pop to get leaves you
    > with the old problem: you have to drop the check for
    > emptyness of kwargs since legal arguments are not removed
    > after use. If, on the other hand, you remove this check,
    > erraneous (p.e. misspelled) arguments are just silently
    > ignored.

    > Maybe, a wrapper would solve the problem? How would one
    > code a replacement for pop that works on 2.2 as well?
    > Probably easiest by using get and del within a
    > try..except block? The wrapper could then have a clear
    > note how to replace it once 2.3 becomes mandatory
    > sometimes in the future.

I added a method popd to matplotlib.cbook. It should work just like
d.pop(key) but you call popd(d, key). Like pop, it accepts a default

Before we reapply your patch to raise on bad kwargs, I think it's
worth getting some input if we want to raise on nonexistent keys. In
some cases, it might be desirable to be able to do, for example

  legend(handles, labels, linewidth=2, fontsize=12)

From an implementation standpoint, it's easiest to implement something
like this using anonymous **kwargs, and iterate over all the handles
and text objects calling set_someprop(val) if set_someprop exists for
some object.

Ie, rather than making all the keyword args explicit and therefore
having to add explicitly add all the setters for line, text and patch
to the kwargs of Legend, which would become a maintenance problem
(duplication of properties throughout the code), one possible design
is to just put a blanket kwargs at the end and define an Artist update
method to look like (freestyle coding here...)

def update(self, **kwargs):
    for key, val in kwargs.items():
        func = getattr(self, 'set_'+key, None)
        if func is None or not callable(func): continue
Then we could do in the legend class

   for o in lines+texts+patches: o.update(kwargs)

The downside of course is that this fails silently if the user
provides a bad kwarg. The upside is it is a very easy, clean
implementation that scales with the addition of new setters to the
underlying objects.


Hi there,

seems like we are synchronizing rather badly in our work and our messages to
the list. :slight_smile:

Before we reapply your patch to raise on bad kwargs, I think it's
worth getting some input if we want to raise on nonexistent keys...

Ok, there's a point. I did not even think that there would be any controversy,
but what you point out should certainly be considered.

Basically, this is a question about the philosophy of properties in general:
Should properties be settable just per-object, or should settings be
propagated to the children. I believe the current state is not fully
consistent in that respect.

What you are proposing is an interesting idea, but if it is adopted, it should
be done in general and not only in certain places. And in that case, it might
become rather complex. Properties would have to be uniquely identifiable by
name only. (I.e. all linewidths have to be called just "linewidth", so an
object that contains different lines that should be configurable
independently have to be split in separate sub-objects) The passing of
properties should happen everywhere in the library - otherwise it will be
more confusing than helpful.

Currently, it seems to me that there is a rather weak distinction between
properties and just plain kwargs. This should probably be sorted out before
adopting a policy of passing all kwargs on to the children.

And as for silently ignoring unknown arguments: I still do not really like
that idea. It smells like a source of hard to find bugs.



_________________________________________Norbert Nemec
         Bernhardstr. 2 ... D-93053 Regensburg
     Tel: 0941 - 2009638 ... Mobil: 0179 - 7475199
           eMail: <Norbert@...160...>