Skip to content

Commit

Permalink
Merge pull request #1143 from ioam/mpl_get_size
Browse files Browse the repository at this point in the history
Use correct dpi in MPLRenderer.get_size
  • Loading branch information
jlstevens authored Feb 21, 2017
2 parents 938ee7c + 7375c40 commit e5a9a6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions holoviews/plotting/mpl/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def plot_options(cls, obj, percent_size):
@bothmethod
def get_size(self_or_cls, plot):
w, h = plot.state.get_size_inches()
dpi = plot.state.dpi
return (w*dpi, h*dpi)
dpi = self_or_cls.dpi if self_or_cls.dpi else plot.state.dpi
return (int(w*dpi), int(h*dpi))


def diff(self, plot):
Expand Down
32 changes: 32 additions & 0 deletions tests/testrenderclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,38 @@ def test_export_widgets(self):
self.assertEqual(digest_data(data),
'91bbc7b4efebd07b1ee595b902d9899b27f2c7e353dfc87c57c2dfd5d0404301')

def test_get_size_single_plot(self):
plot = self.renderer.get_plot(self.image1)
w, h = self.renderer.get_size(plot)
self.assertEqual((w, h), (400, 400))

def test_get_size_row_plot(self):
plot = self.renderer.get_plot(self.image1+self.image2)
w, h = self.renderer.get_size(plot)
self.assertEqual((w, h), (800, 355))

def test_get_size_column_plot(self):
plot = self.renderer.get_plot((self.image1+self.image2).cols(1))
w, h = self.renderer.get_size(plot)
self.assertEqual((w, h), (400, 702))

def test_get_size_grid_plot(self):
grid = GridSpace({(i, j): self.image1 for i in range(3) for j in range(3)})
plot = self.renderer.get_plot(grid)
w, h = self.renderer.get_size(plot)
self.assertEqual((w, h), (480, 480))

def test_get_size_table(self):
table = Table(range(10), kdims=['x'])
plot = self.renderer.get_plot(table)
w, h = self.renderer.get_size(plot)
self.assertEqual((w, h), (400, 400))

def test_get_size_tables_in_layout(self):
table = Table(range(10), kdims=['x'])
plot = self.renderer.get_plot(table+table)
w, h = self.renderer.get_size(plot)
self.assertEqual((w, h), (800, 320))

class BokehRendererTest(ComparisonTestCase):

Expand Down

0 comments on commit e5a9a6c

Please sign in to comment.