Skip to content

Commit 6b7eaaf

Browse files
committed
fixed bug in test_rotated_labels, fixed test_image_plot, now assert_phash saves output pdf in test directory in case of a failure so you can see wether the picture is flipped or not
1 parent d16336c commit 6b7eaaf

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

matplotlib2tikz/image.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def draw_image(data, obj):
2727
# store the image as in a file
2828
img_array = obj.get_array()
2929

30+
if obj.origin == "lower":
31+
img_array = numpy.flipud(img_array)
32+
3033
dims = img_array.shape
3134
if len(dims) == 2: # the values are given as one real number: look at cmap
3235
clims = obj.get_clim()
3336

34-
if obj.origin == "lower":
35-
img_array = numpy.flipud(img_array)
36-
3737
mpl.pyplot.imsave(fname=filename,
3838
arr=img_array,
3939
cmap=obj.get_cmap(),
@@ -44,8 +44,9 @@ def draw_image(data, obj):
4444
else:
4545
# RGB (+alpha) information at each point
4646
assert len(dims) == 3 and dims[2] in [3, 4]
47-
# convert to PIL image (after upside-down flip)
48-
image = PIL.Image.fromarray(numpy.flipud(img_array))
47+
# convert to PIL image
48+
49+
image = PIL.Image.fromarray(img_array)
4950
image.save(filename)
5051

5152
# write the corresponding information to the TikZ file

test/helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import matplotlib2tikz
44

55
import os
6+
import shutil
67
import tempfile
78
import subprocess
89
from PIL import Image
@@ -93,6 +94,9 @@ def assert_phash(fig, reference_phash):
9394
compute_phash(fig)
9495

9596
if reference_phash != phash:
97+
# Copy pdf_file in test directory
98+
shutil.copy(pdf_file, os.path.dirname(os.path.abspath(__file__)))
99+
96100
# Compute the Hamming distance between the two 64-bit numbers
97101
hamming_dist = \
98102
bin(int(phash, 16) ^ int(reference_phash, 16)).count('1')

test/test_image_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def plot():
1919
fig = pp.figure(figsize=figsize)
2020
ax = pp.axes([0, 0, 1, 1], frameon=False)
2121
ax.set_axis_off()
22-
pp.imshow(lena, origin='lower')
22+
pp.imshow(lena)
2323
# Set the current color map to HSV.
2424
pp.hsv()
2525
pp.colorbar()
2626
return fig
2727

2828

2929
def test():
30-
helpers.assert_phash(plot(), '7558d3b30f634b06')
30+
helpers.assert_phash(plot(), '75c3d34d1d0d4b91')

test/test_rotated_labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_rotated_labels_parameters(x_alignment, y_alignment,
6262
matplotlib2tikz.save(
6363
tikz_file,
6464
figurewidth='7.5cm',
65-
extra=extra_dict
65+
extra_axis_parameters=extra_dict
6666
)
6767

6868
# close figure
@@ -101,7 +101,7 @@ def test_rotated_labels_parameters_different_values(x_tick_label_width,
101101
matplotlib2tikz.save(
102102
tikz_file,
103103
figurewidth='7.5cm',
104-
extra=extra_dict
104+
extra_axis_parameters=extra_dict
105105
)
106106

107107
# close figure

0 commit comments

Comments
 (0)