Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 9 commits into from
Sep 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 13 additions & 4 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,11 +1117,20 @@ def get_extent(self):
-0.5 + self.oy, numrows-0.5 + self.oy)

def make_image(self, renderer, magnification=1.0, unsampled=False):
bbox = Bbox([[self.ox, self.oy],
[self.ox + self._A.shape[1], self.oy + self._A.shape[0]]])
clip = Bbox([[0, 0], [renderer.width, renderer.height]])
fac = renderer.dpi/self.figure.dpi
# fac here is to account for pdf, eps, svg backends where
# figure.dpi is set to 72. This means we need to scale the
# image (using magification) and offset it appropriately.
bbox = Bbox([[self.ox/fac, self.oy/fac],
[(self.ox/fac + self._A.shape[1]),
(self.oy/fac + self._A.shape[0])]])
width, height = self.figure.get_size_inches()
width *= renderer.dpi
height *= renderer.dpi
clip = Bbox([[0, 0], [width, height]])

return self._make_image(
self._A, bbox, bbox, clip, magnification=magnification,
self._A, bbox, bbox, clip, magnification=magnification / fac,
unsampled=unsampled, round_to_pixel_border=False)

def set_data(self, A):
Expand Down
Binary file not shown.
Binary file not shown.
42 changes: 28 additions & 14 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,36 @@ def test_interp_nearest_vs_none():
ax2.set_title('interpolation nearest')


@image_comparison(baseline_images=['figimage-0', 'figimage-1'], extensions=['png'])
def test_figimage():
def do_figimage(suppressComposite):
""" Helper for the next two tests """
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')

@image_comparison(baseline_images=['figimage-0'],
extensions=['png','pdf'])
def test_figimage0():
'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')
suppressComposite = False
do_figimage(suppressComposite)


@image_comparison(baseline_images=['figimage-1'],
extensions=['png','pdf'])
def test_figimage1():
'test the figimage method'
suppressComposite = True
do_figimage(suppressComposite)


def test_image_python_io():
fig = plt.figure()
Expand Down