小编Ale*_*ena的帖子

在 jupyter 实验室中使用交互式绘图时控制图形高度

我正在尝试结合使用 JupyterLab 和最新的 ipywidgets 来拥有一个基本的图形界面来探索一些数据。但是,我找不到为交互式绘图设置图形高度的方法

笔记本加载一些文件,然后用户可以使用小部件(在文本框下方的代码中)传递一些输入。最后,通过按下按钮,生成图形并传递给输出小部件。

这是示例代码:


import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import clear_output, display
import ipywidgets as widgets

data = pd.read_csv('data.csv')

def show_results(input):
    if 'fig' in locals():
        del fig

    with out:
        clear_output(True)
        fig, ax = plt.subplots(1, 1)
        ax.axis('equal')
        data.loc[input.value].plot(cmap='inferno_r', column='probability', ax=ax, legend=True)
        plt.show()


input = widgets.Text(placeholder='input field', description='Input:')

showMe = widgets.Button(
    description='Show me the results',
    tooltip='Show me',
)
out = widgets.Output(layout = {
            'width': '100%',
            'height': '900px',
            'border': '1px solid black'
        })


showMe.on_click(show_results)

display(input) …
Run Code Online (Sandbox Code Playgroud)

matplotlib ipywidgets jupyter-lab

7
推荐指数
1
解决办法
2368
查看次数

标签 统计

ipywidgets ×1

jupyter-lab ×1

matplotlib ×1