Skip to content

Commit cdf20af

Browse files
committed
fix broken scaling plot title
1 parent 38915cc commit cdf20af

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

pypop/metrics/metricset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def plot_scaling(
202202
group_key="auto",
203203
title=None,
204204
fontsize=14,
205+
fit_data_only=False,
205206
**kwargs
206207
):
207208
from pypop.notebook_interface.plotting import ScalingPlot
@@ -213,4 +214,5 @@ def plot_scaling(
213214
group_key=group_key,
214215
title=title,
215216
fontsize=fontsize,
217+
fit_data_only=fit_data_only,
216218
)

pypop/notebook_interface/plotting.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __init__(
158158

159159
self._group_label = group_label if group_label else self._group_key
160160

161-
self._fontsize = fontsize
161+
self.fontsize = fontsize
162162
self._pop_logo = pop_logo
163163

164164
self._metric_name_column_text = []
@@ -173,7 +173,7 @@ def _setup_geometry(self):
173173
self._ncols = len(self._metrics.metric_data.index)
174174

175175
pt_to_px = 96 / 72
176-
font_px = self._fontsize * pt_to_px
176+
font_px = self.fontsize * pt_to_px
177177
self._logo_height = 50
178178
self._logo_subpad = 10
179179
self._cell_height = font_px * 2.2
@@ -245,7 +245,7 @@ def _build_plot(self):
245245
@long_desc
246246
</div>
247247
""".format(
248-
plot_width / 2, self._fontsize - 2, plot_width / 2, self._fontsize - 4
248+
plot_width / 2, self.fontsize - 2, plot_width / 2, self.fontsize - 4
249249
)
250250

251251
hover_tool = HoverTool(
@@ -386,7 +386,7 @@ def _build_plot(self):
386386
text="data",
387387
source=plotdata,
388388
text_baseline="middle",
389-
text_font_size="{}pt".format(self._fontsize),
389+
text_font_size="{}pt".format(self.fontsize),
390390
)
391391

392392
if self._pop_logo:
@@ -441,6 +441,7 @@ def __init__(
441441
group_label=None,
442442
title=None,
443443
fontsize=14,
444+
fit_data_only=False,
444445
**kwargs
445446
):
446447

@@ -458,14 +459,17 @@ def __init__(
458459
if independent_variable == "auto"
459460
else independent_variable
460461
)
462+
461463
self._yaxis_key = scaling_variable
462-
self._fontsize = fontsize
464+
self.fontsize = fontsize
465+
self.fit_data_only = fit_data_only
466+
self.title = title
463467

464468
def _build_plot(self):
465469

466470
# Geometry calculations - currently fix width at 60em height at 40em
467471
pt_to_px = 96 / 72
468-
font_px = self._fontsize * pt_to_px
472+
font_px = self.fontsize * pt_to_px
469473
width = int(48 * font_px)
470474
height = int(32 * font_px)
471475

@@ -502,7 +506,10 @@ def _build_plot(self):
502506
yrange_80pc = 0.8 * yrange_ideal + 0.2
503507

504508
x_axis_range = x_lims
505-
y_axis_range = min(y_lims[0], yrange_ideal[0]), max(y_lims[1], yrange_ideal[1])
509+
if self.fit_data_only:
510+
y_axis_range = y_lims
511+
else:
512+
y_axis_range = min(y_lims[0], yrange_ideal[0]), max(y_lims[1], yrange_ideal[1])
506513

507514
x_expand = numpy.asarray([-0.1, 0.1]) * numpy.abs(numpy.diff(x_lims))
508515
y_expand = numpy.asarray([-0.1, 0.1]) * numpy.abs(numpy.diff(y_lims))
@@ -516,27 +523,28 @@ def _build_plot(self):
516523
sizing_mode="scale_width",
517524
x_range=x_axis_range,
518525
y_range=y_axis_range,
526+
title=self.title
519527
)
520528

521529
self._figure.varea(
522530
xrange_ideal,
523531
y1=yrange_ideal,
524532
y2=yrange_80pc,
525533
fill_color="green",
526-
fill_alpha=0.4,
534+
fill_alpha=0.2,
527535
)
528536
self._figure.varea(
529537
xrange_ideal,
530538
y1=yrange_80pc,
531-
y2=numpy.zeros_like(yrange_80pc),
532-
fill_color="red",
533-
fill_alpha=0.4,
539+
y2=numpy.ones_like(yrange_80pc),
540+
fill_color="green",
541+
fill_alpha=0.1,
534542
)
535543

536-
self._figure.xaxis.axis_label_text_font_size = "{}pt".format(self._fontsize)
537-
self._figure.xaxis.major_label_text_font_size = "{}pt".format(self._fontsize - 1)
538-
self._figure.yaxis.axis_label_text_font_size = "{}pt".format(self._fontsize)
539-
self._figure.yaxis.major_label_text_font_size = "{}pt".format(self._fontsize - 1)
544+
self._figure.xaxis.axis_label_text_font_size = "{}pt".format(self.fontsize)
545+
self._figure.xaxis.major_label_text_font_size = "{}pt".format(self.fontsize - 1)
546+
self._figure.yaxis.axis_label_text_font_size = "{}pt".format(self.fontsize)
547+
self._figure.yaxis.major_label_text_font_size = "{}pt".format(self.fontsize - 1)
540548

541549
self._figure.xaxis.axis_label = self._xaxis_key
542550
self._figure.yaxis.axis_label = self._yaxis_key

0 commit comments

Comments
 (0)