Skip to content

Commit 5a88d93

Browse files
committed
Merge pull request matplotlib#1674 from dmcdougall/fix_svg_flip
Fix SVG flip when svg.image_noscale is True
2 parents 38e4d00 + 8c25664 commit 5a88d93

File tree

5 files changed

+220
-0
lines changed

5 files changed

+220
-0
lines changed

lib/matplotlib/backends/backend_svg.py

+3
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,12 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
743743
self.writer.start(u'g', attrib={u'clip-path': u'url(#%s)' % clipid})
744744

745745
trans = [1,0,0,1,0,0]
746+
h,w = im.get_size_out()
746747
if rcParams['svg.image_noscale']:
747748
trans = list(im.get_matrix())
748749
trans[5] = -trans[5]
750+
trans[3] = -trans[3]
751+
y += h
749752
attrib[u'transform'] = generate_transform([(u'matrix', tuple(trans))])
750753
assert trans[1] == 0
751754
assert trans[2] == 0
Binary file not shown.
Loading
Loading

lib/matplotlib/tests/test_backend_svg.py

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from io import BytesIO
66
import xml.parsers.expat
77
from matplotlib.testing.decorators import knownfailureif, cleanup
8+
from matplotlib.testing.decorators import image_comparison
89

910
@cleanup
1011
def test_visibility():
@@ -30,3 +31,13 @@ def test_visibility():
3031

3132
parser = xml.parsers.expat.ParserCreate()
3233
parser.Parse(buf) # this will raise ExpatError if the svg is invalid
34+
35+
@image_comparison(baseline_images=['noscale'], remove_text=True)
36+
def test_noscale():
37+
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
38+
Z = np.sin(Y**2)
39+
40+
fig = plt.figure()
41+
ax = fig.add_subplot(1, 1, 1)
42+
ax.imshow(Z, cmap='gray')
43+
plt.rcParams['svg.image_noscale'] = True

0 commit comments

Comments
 (0)