Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixed: compare_images for older numpy versions. added: backend_pdf al…
…lows numpy.float32 in pdfRepr
  • Loading branch information
Michael Welter committed Aug 26, 2012
commit 309c93c2e71a7ef8d70deaf1f4d0c6adc77a0472
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def pdfRepr(obj):
# Floats. PDF does not have exponential notation (1.0e-10) so we
# need to use %f with some precision. Perhaps the precision
# should adapt to the magnitude of the number?
elif isinstance(obj, float):
elif isinstance(obj, (float, np.float32)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why we shouldn't use cbook.is_numlike and cbook.is_scalar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmcdougall Why would you want to use cbook.is_numlike or is_scalar here? In any case, it looks like a change to the line in question has already been made by another PR.

@mwelter, I don't think this PR should be touchiung backend_pdf at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efiring Hmmm. I thought a numpy version independent way of checking whether something was a number would be neater. I guess we do actually want floating point numbers here. I can't find a cbook.is_floatlike, so this way is probably better, you're right.

if not np.isfinite(obj):
raise ValueError("Can only output finite numbers in PDF")
r = ("%.10f" % obj).encode('ascii')
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ def compare_images( expected, actual, tol, in_decorator=False ):
h1p = expectedImage[:,:,i]
h2p = actualImage[:,:,i]

h1h = np.histogram(h1p, bins=bins)[0]
h2h = np.histogram(h2p, bins=bins)[0]
h1h = np.histogram(h1p, bins=ns)[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this has been fixed by another PR in a different place (ns became bins). Will look for the PR #.

h2h = np.histogram(h2p, bins=ns)[0]

rms += np.sum(np.power((h1h-h2h), 2))

Expand Down