Thanks for reporting the problem.
I can reproduce this error in the svn trunk.
My diagnosis is that this is because the clip mask is not correctly
set, i.e., the mask path is not properly flipped in the svg backend.
I was able to solve this particular problem using the attached patch.
But, i'm not sure if this patch is a general solution. So, I hope
other developers step in.
Bartosz, below is a workaround you may use meanwhile. Note that the
workaround will give correct result only for svg backend.
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_axes([0.4, 0.4, 0.25, 0.25], polar=True)
# modify the ax.patch transform to work around with svg backend bug
import matplotlib.transforms as mtransforms
flipped_transAxes = mtransforms.BboxTransformTo(ax.bbox) \
+ mtransforms.Affine2D().scale(1.0,
-1.0).translate(0., 72*fig.get_figheight())
ax.patch.set_transform(flipped_transAxes)
ax.xaxis.set_clip_path(ax.patch)
ax.yaxis.set_clip_path(ax.patch)
theta1 = np.pi/4
ax.plot([theta1, theta1], [0, 1], '-')
plt.savefig('test_polar.svg')
plt.savefig('test_polar.png')
Regards,
-JJ
On Wed, Sep 16, 2009 at 2:56 PM, Bartosz Telenczuk
<b.telenc...@biologie.hu-berlin.de> wrote:
> Dear all,
>
> I have a problem with exporting polar plots to SVG. When attached to
> axes which are not centered in the figure, the content (grids, data,
> etc.) seems not to be shifted correctly with the axes. However, when I
> plot it directly to the screen or export to PNG everything is fine.
>
> Here is an example reproducing this error:
>
> import matplotlib.pyplot as plt
> import numpy as np
>
> fig = plt.figure()
> ax = fig.add_axes([0.4, 0.4, 0.25, 0.25], polar=True)
>
> theta1 = np.pi/4
> ax.plot([theta1, theta1], [0, 1], '-')
>
> plt.savefig('test_polar.svg')
> plt.savefig('test_polar.png')
> plt.show()
>
> I was able to reproduce the problem it in matplotlib 0.99.0 (Backend:
> GTKAgg).
>
>
> Cheers,
>
> Bartosz
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9-12, 2009. Register now!
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py
index 31765c8..72a9623 100644
--- a/lib/matplotlib/backends/backend_svg.py
+++ b/lib/matplotlib/backends/backend_svg.py
@@ -164,8 +164,9 @@ class RendererSVG(RendererBase):
def _get_gc_clip_svg(self, gc):
cliprect = gc.get_clip_rectangle()
clippath, clippath_trans = gc.get_clip_path()
+ trans_and_flip = self._make_flip_transform(clippath_trans)
if clippath is not None:
- path_data = self._convert_path(clippath, clippath_trans)
+ path_data = self._convert_path(clippath, trans_and_flip)
path = '<path d="%s"/>' % path_data
elif cliprect is not None:
x, y, w, h = cliprect.bounds
@@ -211,10 +212,14 @@ class RendererSVG(RendererBase):
}
def _make_flip_transform(self, transform):
- return (transform +
- Affine2D()
- .scale(1.0, -1.0)
- .translate(0.0, self.height))
+ if transform is not None:
+ return (transform +
+ Affine2D()
+ .scale(1.0, -1.0)
+ .translate(0.0, self.height))
+ else:
+ return Affine2D().scale(1.0, -1.0).translate(0.0, self.height)
+
def _convert_path(self, path, transform, clip=False):
path_data = []
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users