matplotlib / matplotlib/ipympl

Getting back toolbar on left (if set to top position) in 0.8.4?

未关闭
#411 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Jupyter Notebook
星标
1.7k
派生
234
PR 合并指标
30 天内没有已合并 PR

描述

## Describe the issue

In an earlier version of ipympl (unfortunately, haven't recorded which), if I chose the positioning of the toolbar on top, it was automatically placed on the left; I have a partial record of that here - https://stackoverflow.com/questions/69106967/jupyter-matplotlib-widget-place-toolbar-horizontally-over-plot

However, I made an update recently, and it turns out, the hacks that I have documented previously, do not work anymore - also because now the default for `fig.canvas.toolbar_visible` seems to be `fade-in-fade-out` (apparently, when I documented above hacks, the default was `visible`).

So now, if you run the last code snippet in the answer of the linked SO post above (only thing I added was version printout):

```python
%matplotlib widget
import ipympl; print("ipympl version {}".format(ipympl.__version__))

import matplotlib.pyplot as plt
from ipywidgets import widgets, Layout
from IPython.display import display, HTML

out_widget_plot = widgets.Output()
with out_widget_plot:
with plt.style.context("default"): # ggplot
fig, (ax1) = plt.subplots(1, 1)

fig.suptitle('test title', fontsize=10)
tline = ax1.plot([0,1,2], [10,20,30])
fig.tight_layout()
#fig.canvas.toolbar.button_style = 'info' # test: ok, works (but don't need it here)
#fig.canvas.toolbar.orientation = 'horizontal' # no error, but no effect either
fig.canvas.toolbar_position = 'top' # this also switches the orientation to horizontal, too
fig.canvas.header_visible = False # Gets rid of "Figure 1" on top

# the below CSS style override in Jupyter, allows the div that hosts the Matplotlib toolbar, to be placed "on top" of the div that hosts the plot:
# widget-label does the same, but for the bottom "x/y" indicator (which is why its position needs to also be controlled with margin)
sthtml = """

.jupyter-matplotlib-toolbar {
overflow: visible;
position: absolute;
z-index: 1000;
}
.widget-label {
color: var(--jp-widgets-label-color);
font-size: var(--jp-widgets-font-size);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
line-height: var(--jp-widgets-inline-height);
z-index: 1000;
margin-top: -41px;
margin-left: 58px;
}

"""

the_ui = widgets.VBox([ widgets.HTML(sthtml), widgets.HTML("Hello"), out_widget_plot, widgets.HTML("World"),])
display(the_ui)
```

... you at first do not get any toolbar menu (because due to the `fade-in-fade-out`, the menu is not shown, if the mouse cursor is not over the plot widget), then when you mouseover, you get the toolbar to the right (and there is no "hamburger" icon at first, that used to collapse/expand the rest of the toolbar; and the plot figure rendered after the two HTML "labels", "Hello" and "World"):

![image](https://user-images.githubusercontent.com/48317456/146895571-1d900979-8cf6-40c6-b77e-ebe805962fcc.png)

... whereas the same code earlier showed a toolbar on the left (and there is "hamburger" icon at first, that used to collapse/expand the rest of the toolbar, shown; and the plot being rendered *between* the two HTML "labels") :

![](https://i.stack.imgur.com/0XksL.png)

Note also that now, the figure plot widget is not shown anymore between the "Hello" and the "World" labels - whereas previously it was (which was the intention).

Is there any way I can get the old behavior back, so I can place the toolbar on the top left, and have the figure shown between other widgets (and possibly get the "hamburger" expand/collapse button back)?

## Versions

```
3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0]
ipympl version: 0.8.4
Selected Jupyter core packages...
IPython : 7.30.1
ipykernel : 6.6.0
ipywidgets : 7.6.5
jupyter_client : 7.1.0
jupyter_core : 4.9.1
jupyter_server : 1.13.1
jupyterlab : not installed
nbclient : 0.5.9
nbconvert : 6.3.0
nbformat : 5.1.3
notebook : 6.4.6
qtconsole : 5.2.2
traitlets : 5.1.1
Known nbextensions:
config dir: /usr/local/etc/jupyter/nbconfig
notebook section
bqplot/extension enabled
- Validating: OK
ipysheet/extension enabled
- Validating: OK
ipyvolume/extension enabled
- Validating: OK
jupyter-datawidgets/extension enabled
- Validating: OK
jupyter-leaflet/extension enabled
- Validating: OK
jupyter-matplotlib/extension enabled
- Validating: OK
jupyter-threejs/extension enabled
- Validating: OK
jupyter-webrtc/extension enabled
- Validating: OK
jupyter_bokeh/extension enabled
- Validating: OK
jupyter_resource_usage/main enabled
- Validating: OK
jupyterlab-plotly/extension enabled
- Validating: OK
voila/extension enabled
- Validating: OK
jupyter-js-widgets/extension enabled
- Validating: OK
nbextensions_configurator/config_menu/main enabled
- Validating: problems found:
- require? X nbextensions_configurator/config_menu/main
contrib_nbextensions_help_item/main enabled
- Validating: OK
tree section
nbextensions_configurator/tree_tab/main enabled
- Validating: problems found:
- require? X nbextensions_configurator/tree_tab/main
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
[--paths] [--json] [--debug]
[subcommand]

Jupyter: Interactive Computing

positional arguments:
subcommand the subcommand to launch

optional arguments:
-h, --help show this help message and exit
--version show the versions of core jupyter packages and exit
--config-dir show Jupyter config dir
--data-dir show Jupyter data dir
--runtime-dir show Jupyter runtime dir
--paths show all Jupyter paths. Add --json for machine-readable
format.
--json output paths as machine-readable json
--debug output debug information about paths

Available subcommands: bundlerextension console contrib dejavu execute kernel
kernelspec migrate nbconvert nbextension nbextensions_configurator notebook
qtconsole run server serverextension troubleshoot trust

Jupyter command `jupyter-labextension` not found.
```

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 ipympl 0.8.4 以及所列出的 Jupyter 和 ipywidgets 版本运行提供的复现,然后将工具栏和 widget 布局的行为与之前的示例进行比较。完成的标准是恢复工具栏位于左上角的布局,使图形保持在 Hello 和 World widget 之间,并确定是否可以恢复汉堡菜单控件。

由索引模型根据 Issue 内容生成。

评估

技术栈
jupyter-notebook, python
领域
frontend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。