Skip to content

Commit 99c417e

Browse files
committed
changed test_image_plot into two test one for rgb and another for monochrome pictures
1 parent cffe867 commit 99c417e

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

matplotlib2tikz/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def draw_image(data, obj):
4646
assert len(dims) == 3 and dims[2] in [3, 4]
4747
# convert to PIL image
4848
image = PIL.Image.fromarray(img_array)
49-
image.save(filename)
49+
image.save(filename, origin=obj.origin)
5050

5151
# write the corresponding information to the TikZ file
5252
extent = obj.get_extent()

test/test_image_plot.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# -*- coding: utf-8 -*-
22
#
33
import helpers
4+
from matplotlib import rcParams
5+
from matplotlib import pyplot as pp
6+
import pytest
7+
import os
48

9+
try:
10+
from PIL import Image
11+
except ImportError:
12+
raise RuntimeError('PIL must be installed to run this example')
513

6-
def plot():
7-
from matplotlib import rcParams
8-
from matplotlib import pyplot as pp
9-
import os
10-
try:
11-
from PIL import Image
12-
except ImportError:
13-
raise RuntimeError('PIL must be installed to run this example')
14+
#the picture 'lena.png' with origin='lower' is flipped upside-down. So it has to be upside-down in the pdf-file as well.
15+
16+
def plot1(): #test for monochrome picture
1417

1518
this_dir = os.path.dirname(os.path.realpath(__file__))
1619
lena = Image.open(os.path.join(this_dir, 'lena.png'))
@@ -26,6 +29,29 @@ def plot():
2629
pp.colorbar()
2730
return fig
2831

32+
def plot2(): #test for rgb picture
33+
34+
this_dir = os.path.dirname(os.path.realpath(__file__))
35+
lena = Image.open(os.path.join(this_dir, 'lena.png'))
36+
dpi = rcParams['figure.dpi']
37+
figsize = lena.size[0] / dpi, lena.size[1] / dpi
38+
fig = pp.figure(figsize=figsize)
39+
ax = pp.axes([0, 0, 1, 1], frameon=False)
40+
ax.set_axis_off()
41+
pp.imshow(lena, cmap='viridis', origin='lower')
42+
# Set the current color map to HSV.
43+
pp.hsv()
44+
pp.colorbar()
45+
return fig
46+
47+
@pytest.mark.parametrize(
48+
'plot, phash', [
49+
(plot1, '455361ec211d72fb'),
50+
(plot2, '7558d3b30f634b06'),
51+
]
52+
)
53+
54+
def test(plot, phash):
55+
helpers.assert_phash(plot(), phash)
56+
return
2957

30-
def test():
31-
helpers.assert_phash(plot(), '455361ec211d72fb')

0 commit comments

Comments
 (0)