gpt4 book ai didi

python - Jupyter 中 bqplot 图形的更紧凑布局

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:05 32 4
gpt4 key购买 nike

我使用 bqplot 在 Jupyter notebook 中创建了多个绘图。这些图已使用 Jupyter 小部件 HBox 和 VBox 布局属性进行排列。但是,我无法弄清楚如何在子图行之间获得紧凑的布局。获得更紧凑布局的最佳方法是什么?

下面是在 Jupyter notebook 中运行的 Python 代码示例。

import numpy as np
from bqplot import *
from IPython.display import Javascript, display, clear_output
import ipywidgets as widgets

size = 100
scale = 100.
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size) * scale)

x_sc = LinearScale()
y_sc = LinearScale()

ax_x = Axis(label='X', scale=x_sc, grid_lines='solid')
ax_y = Axis(label='Y', scale=y_sc, orientation='vertical', grid_lines='solid')

line = Lines(x=x_data, y=x_data, scales={'x': x_sc, 'y': y_sc})

figy=[]
for i in range(2):
figx=[]
for j in range(3):
figx.append(Figure(axes=[ax_x, ax_y], marks=[line], title='Example' + str(i*3+j), fig_margin = dict(top=30, bottom=10, left=20, right=20)))
figy.append(widgets.HBox(figx))
display(widgets.VBox(figy, align_content = 'stretch'))

enter image description here

最佳答案

解决方法:

import numpy as np
from bqplot import *
from IPython.display import Javascript, display, clear_output
import ipywidgets as widgets

size = 100
scale = 100.
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size) * scale)

x_sc = LinearScale()
y_sc = LinearScale()

ax_x = Axis(label='X', scale=x_sc, grid_lines='solid')
ax_y = Axis(label='Y', scale=y_sc, orientation='vertical', grid_lines='solid')

line = Lines(x=x_data, y=x_data, scales={'x': x_sc, 'y': y_sc})

fig_layout = widgets.Layout(width='auto', height='auto')

figy=[]
for i in range(2):
figx=[]
for j in range(3):
figx.append(Figure(layout=fig_layout, axes=[ax_x, ax_y], marks=[line], title='Example' + str(i*3+j), fig_margin = dict(top=30, bottom=10, left=20, right=20)))
figy.append(widgets.HBox(figx))
display(widgets.VBox(figy, align_content = 'stretch'))

基本上覆盖了图形的 layout 属性。 bqplot 图形具有固定的自然高度。

enter image description here

关于python - Jupyter 中 bqplot 图形的更紧凑布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44657772/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com