-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Get proper renderer width and height in FigureImage #9204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This definitely needs a test adding! Could you add your example in the bug report to |
Changig to WIP - see below, but For the tests, there is already the test below, but as you can see it is only set to check @image_comparison(baseline_images=['figimage-0', 'figimage-1'], extensions=['png'])
def test_figimage():
'test the figimage method'
for suppressComposite in False, True:
fig = plt.figure(figsize=(2,2), dpi=100)
fig.suppressComposite = suppressComposite
x,y = np.ix_(np.arange(100.0)/100.0, np.arange(100.0)/100.0)
z = np.sin(x**2 + y**2 - x*y)
c = np.sin(20*x**2 + 50*y**2)
img = z + c/5
fig.figimage(img, xo=0, yo=0, origin='lower')
fig.figimage(img[::-1,:], xo=0, yo=100, origin='lower')
fig.figimage(img[:,::-1], xo=100, yo=0, origin='lower')
fig.figimage(img[::-1,::-1], xo=100, yo=100, origin='lower') Unfortunately this turns up a continued error, and I'm not quite sure how to get around it... If I modify the above to run from the command line: import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
for suppressComposite in False, True:
fig = plt.figure(figsize=(2,2), dpi=100)
fig.suppressComposite = suppressComposite
x,y = np.ix_(np.arange(100.0)/100.0, np.arange(100.0)/100.0)
z = np.sin(x**2 + y**2 - x*y)
c = np.sin(20*x**2 + 50*y**2)
img = z + c/5
fig.figimage(img, xo=0, yo=0, origin='lower')
fig.figimage(img[::-1,:], xo=0, yo=100, origin='lower')
fig.figimage(img[:,::-1], xo=100, yo=0, origin='lower')
fig.figimage(img[::-1,::-1], xo=100, yo=100, origin='lower')
if suppressComposite:
fig.savefig('Boo.pdf')
fig.savefig('Boo.png')
else:
fig.savefig('Boo2.pdf')
fig.savefig('Boo2.png') For So, somehow the backends are getting the |
OK, so the For |
@dstansby the test is the existing |
Todo: remove or fix the svg test... |
lib/matplotlib/tests/test_image.py
Outdated
'test the figimage method' | ||
|
||
for suppressComposite in False, True: | ||
for suppressComposite in [False]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned that we are losing testing the supressComposite=True
code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, never mind, I should have read the next part of diff 🐑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe I should clean this a bit. The for-loop worked when the test only did png
, but never got to the second pdf for some reason. This (ahem) "fixed" the problem.
lib/matplotlib/tests/test_image.py
Outdated
'test the figimage method' | ||
|
||
for suppressComposite in False, True: | ||
for suppressComposite in [False]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, never mind, I should have read the next part of diff 🐑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
FIX: Get proper renderer width and height in FigureImage
Thanks! backported to v2.1.x as 052b52b |
Possible fix to #9203. Works with their example.
Issue was that
renderer.width
would return 1.0, but we really neededwidth, height = renderer.get_canvas_width_height()
.Their test was:
PR Summary
PR Checklist