Re: [matplotlib-devel] python-2.6 compatible matplotlib

2009-04-24 Thread Ryan May
On Thu, Apr 9, 2009 at 8:18 PM, Adam Mercer  wrote:

> On Thu, Apr 9, 2009 at 13:46, Michael Droettboom  wrote:
> > I did a lot of the initial fixes for Python 2.6 within the first week of
> the
> > 2.6.0 release -- they were mostly of the warning/style nature.  I've been
> > running it on 2.6 on and off ever since, so it should be ok.  But let us
> > know if you find anything.
>
> The only things I've seen so far are some deprecation warnings of the form:
>
>
> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/texmanager.py:55:
> DeprecationWarning: os.popen4 is deprecated.  Use the subprocess
> module.
>  stdin, stdout = os.popen4('dvipng -version')
>

I fixed this in r7063.  It works for me on Linux, but the windows users
might want to double check that there isn't some weird subprocess
incompatibility. (tex_demo.py exercises this code.)

I also fixed the use of os.popen in cbook.report_memory().  Again, it works
for me here, but I'd love for others to check.  There is no code for windows
with this one, but there is code for Macs.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States
--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Problem saving to eps with usetex=True

2009-04-24 Thread Jae-Joon Lee
ps backend, when usetex=True, uses latex with psfrag package to
generate the output (with some extra steps).
It seems that the bounding box information is not correctly recovered
during this process.
I first thought that it would be quite difficult to get this correct,
however the attached (relatively simple) patch seems to work fine.

Ken, can you try the patch and see if it works?

-JJ




On Thu, Apr 23, 2009 at 2:25 PM, Ken Schutte  wrote:
> I've been trying to track down some strange behavior I was getting,
> and I think narrowed it down to some code that I'll paste below.
>
> I'm trying to write to .eps files, and when I have usetex=True,
> something is screwed up with the padding on the left, and eventually
> the whole image is just white.
>
> If I run this script, the 'testA-*.eps' look good, but 'testB-*' does
> not.  The same problem happens even if I remove the ticklabels.
>
> Any tips would be appreciated.
> thanks,
> Ken
>
>
>
> 
> import matplotlib.pyplot as plt
> import numpy as np
> from matplotlib import rc
>
> fig = plt.figure()
> ax = fig.add_axes([0,0,1,1],frameon=False)
>
> X = np.tile(np.arange(500),(10,1))  # (10,500) shape
>
> ax.imshow(X,interpolation='nearest',aspect='auto')
>
> def go(name):
>
>    for d in (1,2,3,4):
>
>        w = d*5
>        h = d
>
>        fig.set_size_inches(w,h)
>        fig.savefig("%s-%d.eps" % (name,d))
>
> rc('text', usetex=False)
> go("testA")
>
> rc('text', usetex=True)
> go("testB")
>
> --
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> ___
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
Index: lib/matplotlib/backends/backend_ps.py
===
--- lib/matplotlib/backends/backend_ps.py	(revision 7061)
+++ lib/matplotlib/backends/backend_ps.py	(working copy)
@@ -1096,17 +1096,22 @@
 isLandscape = True
 width, height = height, width
 bbox = (lly, llx, ury, urx)
-temp_papertype = _get_papertype(width, height)
-if papertype=='auto':
-papertype = temp_papertype
-paperWidth, paperHeight = papersize[temp_papertype]
+
+if isEPSF:
+paperWidth, paperHeight = self.figure.get_size_inches()
 else:
-paperWidth, paperHeight = papersize[papertype]
-if (width>paperWidth or height>paperHeight) and isEPSF:
+temp_papertype = _get_papertype(width, height)
+if papertype=='auto':
+papertype = temp_papertype
 paperWidth, paperHeight = papersize[temp_papertype]
-verbose.report('Your figure is too big to fit on %s paper. %s \
-paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful')
+else:
+paperWidth, paperHeight = papersize[papertype]
+if (width>paperWidth or height>paperHeight) and isEPSF:
+paperWidth, paperHeight = papersize[temp_papertype]
+verbose.report('Your figure is too big to fit on %s paper. %s \
+paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful')
 
+
 texmanager = renderer.get_texmanager()
 font_preamble = texmanager.get_font_preamble()
 custom_preamble = texmanager.get_custom_preamble()
@@ -1247,8 +1252,8 @@
 os.remove(outfile)
 os.remove(tmpfile)
 shutil.move(psfile, tmpfile)
-if eps:
-pstoeps(tmpfile, bbox)
+#if eps:
+#pstoeps(tmpfile, bbox)
 
 
 def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Rasterized artists have wrong transform

2009-04-24 Thread Jae-Joon Lee
Hi Eric,

>
> Sorry about the broken links. I've attached a diff made against trunk
> from a few days ago.

Thanks!

>
> The discussion about what to do with my patch fizzled. I created a
> decorator that made mixed-mode switching a one-line change per artist
> type. I also added get/set_rasterized and an _rasterized attribute to
> the Artist base class. I've used it on and off for a few months now
> with no noted bugs.
>
> If we don't like the decorator, we can just make a helper function
> that is called at the beginning of every artist.draw() method. It's
> not a very complicated modification.
>
>

Would there be a case that draw methods of some Artists do not need to
be decorated?
If not, I guess some metaclass black magic might be not harmful. What
do you think? I'm attaching modified version of your patch which
utilize metaclass for decoration.

I personally want that rasterization is also supported in the ps
backend. I guess the missing support of alpha composition would be a
problem. But, in most of the my use case, I want rasterization for
artist with z lower than some specified value (i.e., background images
using pcolormesh), so it is not a problem for me.

Regards,

-JJ


>>
>> Are you planning to commit your patch to the trunk? I'll be glad to
>> help you if there are any issues.
>
>
> I'd love to get the patch in trunk, if only so that more people can
> try it out and find things to improve (or re-implement).
>
> Thanks,
> Eric
>
Index: lib/matplotlib/artist.py
===
--- lib/matplotlib/artist.py	(revision 7065)
+++ lib/matplotlib/artist.py	(working copy)
@@ -22,12 +22,49 @@
 # http://groups.google.com/groups?hl=en&lr=&threadm=mailman.5090.1098044946.5135.python-list%40python.org&rnum=1&prev=/groups%3Fq%3D__doc__%2Bauthor%253Ajdhunter%2540ace.bsd.uchicago.edu%26hl%3Den%26btnG%3DGoogle%2BSearch
 
 
+
+
+def hook_before_after_draw(draw):
+"""
+Decorator for Artist.draw method. Provides routines
+that run before and after the draw call. The before and after functions
+are useful for changing artist-dependant renderer attributes or making
+other setup function calls, such as starting and flushing a mixed-mode
+renderer.
+"""
+
+def draw_wrapper(artist, renderer):
+if artist.get_rasterized():
+renderer.start_rasterizing()
+draw(artist, renderer)
+renderer.stop_rasterizing()
+else:
+draw(artist, renderer)
+
+# "safe wrapping" to exactly replicate anything we haven't overridden above
+draw_wrapper.__name__ = draw.__name__
+draw_wrapper.__dict__ = draw.__dict__
+draw_wrapper.__doc__  = draw.__doc__
+return draw_wrapper
+
+
+class RasterizedArtistType(type):
+def __new__(meta, name, bases, dct):
+if "draw" in dct:
+_draw = dct["draw"]
+#dct["_draw_original"] = _draw
+dct["draw"] = hook_before_after_draw(_draw)
+return type.__new__(meta, name, bases, dct)
+
+
 class Artist(object):
 """
 Abstract base class for someone who renders into a
 :class:`FigureCanvas`.
 """
 
+__metaclass__ = RasterizedArtistType
+
 aname = 'Artist'
 zorder = 0
 def __init__(self):
@@ -45,6 +82,7 @@
 self._label = ''
 self._picker = None
 self._contains = None
+self._rasterized = None
 
 self.eventson = False  # fire events only if eventson
 self._oid = 0  # an observer id
@@ -511,6 +549,19 @@
 gc.set_clip_rectangle(None)
 gc.set_clip_path(None)
 
+def get_rasterized(self):
+return self._rasterized
+
+def set_rasterized(self, rasterized):
+"""
+Force rasterized (bitmap) drawing in vector backend output.
+
+Defaults to None, which implies the backend's default behavior
+
+ACCEPTS: [True | False | None]
+"""
+self._rasterized = rasterized
+
 def draw(self, renderer, *args, **kwargs):
 'Derived classes drawing method'
 if not self.get_visible(): return
--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel