Repository navigation
Get proper renderer width and height in FigureImage - #9204
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... |
| 'test the figimage method' | ||
|
|
||
| for suppressComposite in False, True: | ||
| for suppressComposite in [False]: |
There was a problem hiding this comment.
I am a bit concerned that we are losing testing the supressComposite=True code path.
There was a problem hiding this comment.
Oh, never mind, I should have read the next part of diff 🐑
There was a problem hiding this comment.
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.
| 'test the figimage method' | ||
|
|
||
| for suppressComposite in False, True: | ||
| for suppressComposite in [False]: |
There was a problem hiding this comment.
Oh, never mind, I should have read the next part of diff 🐑
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.widthwould return 1.0, but we really neededwidth, height = renderer.get_canvas_width_height().Their test was:
PR Summary
PR Checklist