Skip to content

Commit

Permalink
Merge pull request matplotlib#1674 from dmcdougall/fix_svg_flip
Browse files Browse the repository at this point in the history
Fix SVG flip when svg.image_noscale is True
  • Loading branch information
dmcdougall committed Jan 18, 2013
2 parents 38e4d00 + 8c25664 commit 5a88d93
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,12 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
self.writer.start(u'g', attrib={u'clip-path': u'url(#%s)' % clipid})

trans = [1,0,0,1,0,0]
h,w = im.get_size_out()
if rcParams['svg.image_noscale']:
trans = list(im.get_matrix())
trans[5] = -trans[5]
trans[3] = -trans[3]
y += h
attrib[u'transform'] = generate_transform([(u'matrix', tuple(trans))])
assert trans[1] == 0
assert trans[2] == 0
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 206 additions & 0 deletions lib/matplotlib/tests/baseline_images/test_backend_svg/noscale.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from io import BytesIO
import xml.parsers.expat
from matplotlib.testing.decorators import knownfailureif, cleanup
from matplotlib.testing.decorators import image_comparison

@cleanup
def test_visibility():
Expand All @@ -30,3 +31,13 @@ def test_visibility():

parser = xml.parsers.expat.ParserCreate()
parser.Parse(buf) # this will raise ExpatError if the svg is invalid

@image_comparison(baseline_images=['noscale'], remove_text=True)
def test_noscale():
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
Z = np.sin(Y**2)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.imshow(Z, cmap='gray')
plt.rcParams['svg.image_noscale'] = True

0 comments on commit 5a88d93

Please sign in to comment.