Skip to content

Commit 62409b4

Browse files
authored
Merge pull request #275 from s22s/feature/tile_render_scaling
Tile render adjustments
2 parents 109dd45 + 0a512be commit 62409b4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pyrasterframes/src/main/python/pyrasterframes/rf_ipython.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import pyrasterframes.rf_types
2222

2323

24-
def tile_to_png(tile):
24+
def tile_to_png(tile, fig_size=None):
2525
""" Provide image of Tile."""
2626
if tile.cells is None:
2727
return None
@@ -31,10 +31,11 @@ def tile_to_png(tile):
3131
from matplotlib.figure import Figure
3232

3333
# Set up matplotlib objects
34-
[width, height] = tile.dimensions()
35-
dpi = 300
36-
nominal_size = 5.5 # approx full size for a 256x256 tile
37-
fig = Figure(figsize=(nominal_size * width / dpi, nominal_size * height / dpi))
34+
nominal_size = 4 # approx full size for a 256x256 tile
35+
if fig_size is None:
36+
fig_size = (nominal_size, nominal_size)
37+
38+
fig = Figure(figsize=fig_size)
3839
canvas = FigureCanvas(fig)
3940
axis = fig.add_subplot(1, 1, 1)
4041

@@ -43,18 +44,19 @@ def tile_to_png(tile):
4344
axis.xaxis.set_ticks([])
4445
axis.yaxis.set_ticks([])
4546

46-
axis.set_title('{}, {}'.format(tile.dimensions(), tile.cell_type.__repr__())) # compact metadata as title
47+
axis.set_title('{}, {}'.format(tile.dimensions(), tile.cell_type.__repr__()),
48+
fontsize=fig_size[0]*4) # compact metadata as title
4749

4850
with io.BytesIO() as output:
4951
canvas.print_png(output)
5052
return output.getvalue()
5153

5254

53-
def tile_to_html(tile):
55+
def tile_to_html(tile, fig_size=None):
5456
""" Provide HTML string representation of Tile image."""
5557
import base64
5658
b64_img_html = '<img src="data:image/png;base64,{}" />'
57-
png_bits = tile_to_png(tile)
59+
png_bits = tile_to_png(tile, fig_size)
5860
b64_png = base64.b64encode(png_bits).decode('utf-8').replace('\n', '')
5961
return b64_img_html.format(b64_png)
6062

@@ -76,7 +78,7 @@ def pandas_df_to_html(df):
7678

7779
def _safe_tile_to_html(t):
7880
if isinstance(t, pyrasterframes.rf_types.Tile):
79-
return tile_to_html(t)
81+
return tile_to_html(t, fig_size=(2, 2))
8082
else:
8183
# handles case where objects in a column are not all Tile type
8284
return t.__repr__()

0 commit comments

Comments
 (0)