From: Bartosz Telenczuk <b.telenczuk@bi...>  20090916 19:32:47

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 
From: JaeJoon Lee <lee.joon@gm...>  20090916 22:37:20
Attachments:
svg_clip.diff

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.telenczuk@...> 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 912, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: Michael Droettboom <mdroe@st...>  20090917 14:33:34

Thanks. I think you're right, JaeJoon. I've committed a slightly simplified version of your patch on the 0.99 branch and trunk. Mike JaeJoon Lee wrote: > 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.telenczuk@...> 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 912, 2009. Register now! >> http://p.sf.net/sfu/devconf >> _______________________________________________ >> Matplotlibusers mailing list >> Matplotlibusers@... >> https://lists.sourceforge.net/lists/listinfo/matplotlibusers >> >> >>  >> >>  >> 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 912, 2009. Register now! >> http://p.sf.net/sfu/devconf >>  >> >> _______________________________________________ >> Matplotlibusers mailing list >> Matplotlibusers@... >> https://lists.sourceforge.net/lists/listinfo/matplotlibusers  Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA 
From: Bartosz Telenczuk <b.telenczuk@bi...>  20090918 16:13:16

Dear JaeJoon, Your workaround worked perfectly! Thanks a lot! Cheers, Bartosz 