Skip to content

Commit 755d477

Browse files
committed
add pop logo to plots
1 parent d5c61c9 commit 755d477

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pypop/notebook_interface/plotting.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy
77
import pandas
88
import warnings
9+
from pkg_resources import resource_filename
910

1011
from bokeh.plotting import figure
1112
from bokeh.colors import RGB
@@ -28,6 +29,8 @@
2829
module="bokeh.plotting.helpers",
2930
)
3031

32+
POP_LOGO_PNG = "pop_logo.npy"
33+
3134

3235
def get_any_webdriver():
3336

@@ -129,6 +132,7 @@ def __init__(
129132
title=None,
130133
columns_label=None,
131134
fontsize=14,
135+
pop_logo=True,
132136
**kwargs
133137
):
134138
self._metrics = metrics
@@ -144,6 +148,8 @@ def __init__(
144148
self._group_label = group_label if group_label else self._group_key
145149

146150
self._fontsize = fontsize
151+
self._pop_logo = pop_logo
152+
147153
self._metric_name_column_text = []
148154
self._metric_descriptions = []
149155
self._setup_geometry()
@@ -157,11 +163,16 @@ def _setup_geometry(self):
157163

158164
pt_to_px = 96 / 72
159165
font_px = self._fontsize * pt_to_px
166+
self._logo_height = 50
167+
self._logo_subpad = 10
160168
self._cell_height = font_px * 2.2
161169
self._row_locs = numpy.linspace(
162170
0, -self._cell_height * (self._nrows - 1), self._nrows
163171
)
164172

173+
if self._pop_logo:
174+
self._row_locs -= self._logo_height + self._logo_subpad
175+
165176
# Offset rows if there will be a header row
166177
if self._group_key is not None:
167178
self._row_locs -= self._cell_height
@@ -194,7 +205,7 @@ def _setup_geometry(self):
194205
max_value_em_width, approx_string_em_width("{}".format(keyname))
195206
)
196207

197-
self._border_pad = 20 # px
208+
self._border_pad = 10 # px
198209
self._left_pad = font_px / 2
199210
self._right_pad = font_px / 3
200211
self._metric_column_width = 1.1 * (
@@ -360,6 +371,18 @@ def _build_plot(self):
360371
text_font_size="{}pt".format(self._fontsize),
361372
)
362373

374+
if self._pop_logo:
375+
pop_img = resource_filename(__name__, POP_LOGO_PNG)
376+
pop_data = numpy.load(pop_img)
377+
img_h = pop_data.shape[0]
378+
img_w = pop_data.shape[1]
379+
380+
render_h = self._logo_height
381+
render_w = self._logo_height * img_w / img_h
382+
self._figure.image_rgba(
383+
image=[pop_data], x=20, y=-self._logo_height, dw=render_w, dh=render_h
384+
)
385+
363386
self.update()
364387

365388
def efficiency_cmap(self, value):
54.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)