forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridspec_engine.py
40 lines (32 loc) · 1.18 KB
/
gridspec_engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from matplotlib.gridspec import GridSpec
import math
def defaultGridspecGrid(number):
if number == 3:
return [3, 1]
root = math.sqrt(number)
if root - math.floor(root) == 0.0:
return [int(root), int(root)]
col = int(math.ceil(root))
row = col - 1
if number <= row * col:
return [row, col]
else:
return [col, col]
class gridspecEngine(object):
def __init__(self, grid=defaultGridspecGrid, max_plot=None):
self._max_plot = max_plot
self.grid = grid
def getGridSpec(self, number):
if number <= 0:
return
if self._max_plot is not None and number > self._max_plot:
print("Number of plot has exceeded the maximum number of " + str(self._max_plot))
return
current_grid = self.grid(number)
return GridSpec(current_grid[0], current_grid[1])