Hi Eric,

Have you find a solution for your problem?
I recently encountered a similar problem.
In my case, the images (I'm rasterizing the pcolormesh) are in wrong
size if the output dpi is other than 72.
And I guess this is related with the changes Jouni made in revision 6730.

So, can you see if you have a correct output with dpi=72?
If that's the case, can you try the attached patch and see if it
solves your problem (should work with dpi other than 72).

I don't quite like my solution but it seems to work.
It passes over the figure instance when initializing the
MixedRenderer, and let the renderer change the dpi of the figure when
changing the backend.
I hope some other developer who better understands the dpi thing take
a look and come up with a better solution.

Regards,

-JJ


On Thu, Feb 19, 2009 at 4:01 PM, Eric Bruning <eric.brun...@gmail.com> wrote:
> I just updated to the latest svn, and unveiled a bug that's evident
> when using mixed-mode rendering in the PDF backend. I'm suspect I'm
> the only one running my patch that enables set_rasterized on a
> per-artist basis, so I'm the only one that's seeing it. :) Artists
> that are left in vector mode are plotted correctly, while artists that
> are rasterized are squished down toward the lower left corner of the
> axes.
>
> Looking at the svn log, I suspect it's the changes to the path
> simplification code (r6847) doing something funky at the transforms
> level. Is that the right place to start looking? Any tips on how to
> track this down?
>
> Thanks,
> Eric
>
>
> Sample code to reproduce the problem:
>
> import numpy
> from matplotlib.pyplot import subplot, get_cmap, scatter, colorbar, show
> basecolors = get_cmap('gist_yarg')
> colormap, normer = basecolors, None #LogNorm()
> x = y = c = numpy.arange(10) +1
> dummy = scatter(x,y,c=c,cmap=colormap)#, norm=normer)
> cbar = colorbar(dummy)#, spacing='proportional',ticks=isolevels.levels)
> dummy.set_rasterized(True)
> dummy.figure.savefig('raster_test.pdf')
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
Index: lib/matplotlib/backends/backend_mixed.py
===================================================================
--- lib/matplotlib/backends/backend_mixed.py	(revision 7000)
+++ lib/matplotlib/backends/backend_mixed.py	(working copy)
@@ -9,7 +9,8 @@
     complex objects, such as quad meshes, are rasterised and then
     output as images.
     """
-    def __init__(self, width, height, dpi, vector_renderer, raster_renderer_class=None):
+    def __init__(self, figure, width, height, dpi, vector_renderer,
+                 raster_renderer_class=None):
         """
         width: The width of the canvas in logical units
 
@@ -38,6 +39,8 @@
         self._raster_renderer = None
         self._rasterizing = 0
 
+        self.figure=figure
+
         self._set_current_renderer(vector_renderer)
 
     _methods = """
@@ -65,6 +68,8 @@
         If start_rasterizing is called multiple times before
         stop_rasterizing is called, this method has no effect.
         """
+        self.figure.set_dpi(self.dpi)
+            
         if self._rasterizing == 0:
             self._raster_renderer = self._raster_renderer_class(
                 self._width*self.dpi, self._height*self.dpi, self.dpi)
@@ -91,6 +96,10 @@
                 image = frombuffer(buffer, w, h, True)
                 image.is_grayscale = False
                 image.flipud_out()
-                self._renderer.draw_image(l, height - b - h, image, None)
+                self._renderer.draw_image(float(l)/self.dpi*72.,
+                                          (float(height) - b - h)/self.dpi*72.,
+                                          image, None)
             self._raster_renderer = None
             self._rasterizing = False
+
+        self.figure.set_dpi(72)
Index: lib/matplotlib/backends/backend_pdf.py
===================================================================
--- lib/matplotlib/backends/backend_pdf.py	(revision 7000)
+++ lib/matplotlib/backends/backend_pdf.py	(working copy)
@@ -1977,8 +1977,8 @@
         else:
             file = PdfFile(filename)
         file.newPage(width, height)
-        renderer = MixedModeRenderer(
-            width, height, 72, RendererPdf(file, image_dpi))
+        renderer = MixedModeRenderer(self.figure,
+            width, height, image_dpi, RendererPdf(file, image_dpi))
         self.figure.draw(renderer)
         renderer.finalize()
         if isinstance(filename, PdfPages): # finish off this page
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to