John,

I will respond to the more philosophical parts of your message later.

I have committed changes to _transforms.* and transforms.py along the 
lines of your suggestions for a quick improvement to the ease of drawing 
with offsets.


> The best way may be for the extension code to provide a shallowcopy
> method and require derived transform classes to implement it.  All
> references will be preserved, but a new object will be created.
> 
> We only need this for SeparableTransformation and
> NonseparableTransformation but the methods will also have to be
> defined virtually in the base classes.
> 
> We have to think about what should be preserved in the shallow
> copies.  For the use case at hand, we want to preserve the references
> to the values but not the offset transform.
> 
I think I got this right--or at least as right as the existing deepcopy 
methods--but it would be good if you, or another c++ wizard, could take 
a look.  The way I have it seems to work as intended, but testing has 
been light, and I don't really know c++.  I have never written any from 
scratch, only modified existing code.

> I'm not so sure that deepcopy is really needed.  I can't think of a
> use case off hand.

I think it is needed for pickling, but I suspect that the screwiness of 
the objects that the _transforms module produces would prevent pickling 
in any case.  Other than that, I don't see any point in the deepcopy 
methods, or the corresponding (and redundant) deepcopy functions in 
transforms.py.  I marked with comments a block that I think should be 
excised from transforms.py.

The convenience function I came up with is transforms.offset_copy:

def offset_copy(trans, fig=None, x=0, y=0, units='inches'):
     '''
     Return a shallow copy of a transform with an added offset.
       args:
         trans is any transform
       kwargs:
         fig is the current figure; it can be None if units are 'dots'
         x, y give the offset in units of 'inches' or 'dots'
         units is 'inches' or 'dots'
     '''
     newtrans = trans.shallowcopy()
     if units == 'dots':
         newtrans.set_offset((x,y), identity_transform())
         return newtrans
     if not units == 'inches':
         raise ValueError('units must be dots or inches')
     if fig is None:
         raise ValueError('For units of inches a fig kwarg is needed')
     tx = Value(x) * fig.dpi
     ty = Value(y) * fig.dpi
     newtrans.set_offset((0,0), translation_transform(tx, ty))
     return newtrans



Minimal testing and illustration of the use of offsets is now in 
examples/transoffset.py.  It includes cartesian and polar coordinates.

Eric

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to