I'm trying to develop an app that presents a grid of Matplotlib figures. While it properly lays out the figures, the default size of the window is way too big for many standard computer monitors. I think this is because QFrame is returning a size hint of 640 x 480.
from enaml.core.api import Looper
from enaml.layout.api import grid
from enaml.widgets.api import Container, MainWindow, MPLCanvas
import matplotlib.pyplot as plt
import numpy as np
def generate_figure():
figure, axes = plt.subplots(1, 1)
axes.plot(np.random.uniform(size=50))
return figure
enamldef Main(MainWindow):
Container:
layout_constraints => ():
plots = [c for c in children if not isinstance(c, Looper)]
constraints = []
for p in plots[1:]:
constraints.append(p.width == plots[0].width)
constraints.append(p.height == plots[0].height)
# Organize into a grid
n_cols = 4
n_rows = 4
rows = []
for i in range(n_rows):
lb = i * n_cols
ub = lb + n_cols
rows.append(plots[lb:ub])
constraints.append(grid(*rows, column_align='width', row_align='v_center'))
return constraints
Looper:
iterable << range(16)
MPLCanvas:
figure << generate_figure()
Is there a way I can change the default size hint for each MPLCanvas so it starts with a more reasonable size (e.g., 300 x 300). If I set the width/height explicitly, e.g.,:
for p in plots:
constraints.append(p.width >= 100)
constraints.append(p.height >= 100)
constraints.append(p.width <= 300)
constraints.append(p.height <= 300)
It starts off at a good size, but then the MPLCanvas objects no longer resize if I change the overall window size. Is there a good way to change the default size hint for the MPLCanvas?
I do realize that I could just create a subplot grid in a single figure, but I want to use Enaml to include some input widgets next to each MPLCanvas.
Brad