Spaces:
Running
Running
Heatmap: Abandoning estimated constants and calculating the external dimensions of the graph using JS and the internal dimensions of the graph
Browse files- analyze_winscore.py +45 -4
analyze_winscore.py
CHANGED
|
@@ -9,6 +9,7 @@ import numpy as np
|
|
| 9 |
from bokeh.plotting import figure
|
| 10 |
from bokeh.models import LabelSet, LogScale, ColumnDataSource, tickers
|
| 11 |
from bokeh.models import LinearColorMapper, HoverTool
|
|
|
|
| 12 |
from bokeh.palettes import Turbo256 # A color palette with enough colors
|
| 13 |
|
| 14 |
# Function to fit a polynomial curve and return the x and y values of the fitted curve
|
|
@@ -222,13 +223,15 @@ def create_heatmap(data_matrix, original_scores,
|
|
| 222 |
FONTSIZE = 9
|
| 223 |
|
| 224 |
n_rows, n_cols = data_matrix.shape
|
| 225 |
-
y_axis_size = 253
|
| 226 |
-
x_axis_size = 278
|
| 227 |
cell_size = 22
|
|
|
|
|
|
|
| 228 |
if plot_width == None:
|
| 229 |
-
|
|
|
|
| 230 |
if plot_height == None:
|
| 231 |
-
|
|
|
|
| 232 |
|
| 233 |
if selected_rows is not None:
|
| 234 |
# Select only the specified rows (models)
|
|
@@ -327,6 +330,44 @@ def create_heatmap(data_matrix, original_scores,
|
|
| 327 |
# Hide the axis labels
|
| 328 |
p.xaxis.visible = x_axis_visible
|
| 329 |
p.yaxis.visible = y_axis_visible
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
return p
|
| 332 |
|
|
|
|
| 9 |
from bokeh.plotting import figure
|
| 10 |
from bokeh.models import LabelSet, LogScale, ColumnDataSource, tickers
|
| 11 |
from bokeh.models import LinearColorMapper, HoverTool
|
| 12 |
+
from bokeh.models import CustomJS
|
| 13 |
from bokeh.palettes import Turbo256 # A color palette with enough colors
|
| 14 |
|
| 15 |
# Function to fit a polynomial curve and return the x and y values of the fitted curve
|
|
|
|
| 223 |
FONTSIZE = 9
|
| 224 |
|
| 225 |
n_rows, n_cols = data_matrix.shape
|
|
|
|
|
|
|
| 226 |
cell_size = 22
|
| 227 |
+
plot_inner_width = None
|
| 228 |
+
plot_inner_height = None
|
| 229 |
if plot_width == None:
|
| 230 |
+
plot_inner_width = n_rows * cell_size
|
| 231 |
+
plot_width = plot_inner_width
|
| 232 |
if plot_height == None:
|
| 233 |
+
plot_inner_height = n_cols * cell_size
|
| 234 |
+
plot_height = plot_inner_height
|
| 235 |
|
| 236 |
if selected_rows is not None:
|
| 237 |
# Select only the specified rows (models)
|
|
|
|
| 330 |
# Hide the axis labels
|
| 331 |
p.xaxis.visible = x_axis_visible
|
| 332 |
p.yaxis.visible = y_axis_visible
|
| 333 |
+
|
| 334 |
+
# Fix inner size
|
| 335 |
+
if plot_inner_width != None:
|
| 336 |
+
p.js_on_change('inner_width', CustomJS(args=dict(p=p, target=plot_inner_width), code="""
|
| 337 |
+
// current inner width of the plot area
|
| 338 |
+
const iw = p.inner_width;
|
| 339 |
+
// calculate the margin between full width and inner plot area
|
| 340 |
+
const margin = p.width - iw;
|
| 341 |
+
// adjust total width so that inner width matches the desired target
|
| 342 |
+
p.width = target + margin;
|
| 343 |
+
|
| 344 |
+
// remove only this callback from the inner_width callbacks array
|
| 345 |
+
const cbs = p.js_property_callbacks.inner_width;
|
| 346 |
+
for (let i = 0; i < cbs.length; i++) {
|
| 347 |
+
if (cbs[i] === this) {
|
| 348 |
+
cbs.splice(i, 1);
|
| 349 |
+
break;
|
| 350 |
+
}
|
| 351 |
+
}
|
| 352 |
+
"""))
|
| 353 |
+
if plot_inner_height != None:
|
| 354 |
+
p.js_on_change('inner_height', CustomJS(args=dict(p=p, target=plot_inner_height), code="""
|
| 355 |
+
// current inner height of the plot area
|
| 356 |
+
const ih = p.inner_height;
|
| 357 |
+
// calculate the margin between full height and inner plot area
|
| 358 |
+
const margin = p.height - ih;
|
| 359 |
+
// adjust total height so that inner height matches the desired target
|
| 360 |
+
p.height = target + margin;
|
| 361 |
+
|
| 362 |
+
// remove only this callback from the inner_height callbacks array
|
| 363 |
+
const cbs = p.js_property_callbacks.inner_height;
|
| 364 |
+
for (let i = 0; i < cbs.length; i++) {
|
| 365 |
+
if (cbs[i] === this) {
|
| 366 |
+
cbs.splice(i, 1);
|
| 367 |
+
break;
|
| 368 |
+
}
|
| 369 |
+
}
|
| 370 |
+
"""))
|
| 371 |
|
| 372 |
return p
|
| 373 |
|