我正在构建一个带有基于Jupyter和Voila 的交互式绘图的 webapp 。里面的笔记本我用ipywidgets处理的交互性和%matplotlib widget后端,所以我可以更新我的阴谋没有重绘全数字(在不工作%matplotlib inline,并%matplotlib notebook在瞧不渲染)。
我的问题是我无法设置图形大小,使其与其画布或容器的大小相匹配,这些画布或容器会在窗口调整大小时自动调整大小。
这是我的情况的一个小工作示例:
%matplotlib widget
from IPython.display import display
import matplotlib.pyplot as plt
import ipywidgets as widgets
import numpy as np
# Output widget that will contain the figure
out = widgets.Output(layout = {
'border': '1px solid black',
# 'width': '100%' # Not needed and does not help
})
# Initializing the figure within out
with out:
fig, ax = plt.subplots(1, constrained_layout=True) …Run Code Online (Sandbox Code Playgroud)