On Thu, Jan 5, 2012 at 11:34 AM, Ryan May <rma...@gmail.com> wrote:
> On Thu, Jan 5, 2012 at 10:58 AM, Benjamin Root <ben.r...@ou.edu> wrote:
> >
> >
> > On Thu, Jan 5, 2012 at 10:40 AM, Benjamin Root <ben.r...@ou.edu> wrote:
> >>
> >>
> >>> At the very least, it would help in compartmentallizing all the
> possible
> >>> drawing attributes that are common across all artists. Currently, I am
> >>> envisioning using a defaultdict object (which was introduced in python
> 2.5)
> >>> or subclassing from it. This might help in keeping compatibility with
> >>> existing code. Subclassing would allow for modifying __get__ and
> __set__ to
> >>> treat some elements like 'c' and 'color', 'lw' and 'linewidth' and so
> on as
> >>> the same.
> >
> >
> > Grrrr, in defaultdict(), the default_factory is called without
> arguments, so
> > a factory can't be made to produce a default value for a given key,
> unless I
> > resort to more hackary...
>
> Might be better to explicitly use properties for this rather than
> overriding dict:
>
> class Style(object):
> __slots__ = ('_lw')
>
> def __init__(self, lw=None):
> self.lw = lw
>
> def _set_linewidth(self, lw):
> self._lw = lw
>
> def _get_linewidth(self):
> return self._lw
>
> lw = property(_get_linewidth, _set_linewidth)
> linewidth = property(_get_linewidth, _set_linewidth)
>
> Declaring slots allows you to keep the available attributes to those
> explicity listed. This way, you can't set a random (misspelled?)
> attribute and wonder for hours why style.edgcolor = 'blue' doesn't
> work.
>
> Ryan
>
>
This is actually a great idea. This codifies in stone the alternative
names of various properties. I have also taken this idea a step further.
Some getter functions, such as for facecolor, will return the value of
color if facecolor is None. This way, we can explicitly code the fallbacks
and relationships the properties have with each other. So far, I have:
'_c', '_ec', '_fc', '_hatch', '_ls', '_lw', '_marker', '_mec', '_mew',
'_mfc', '_mfca', '_ms'
The fallbacks are:
_ec --> _c
_fc --> _c
_mec --> _ec
_mew --> _lw
_mfc --> _fc
_mfca --> _mfc
Any other properties anybody can think of to add?
Ben Root
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users