Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

"Transform()" returns bad coordinates with ipympl

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

还没有人认领这个 Issue。

评估

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

调研方向

首先在 inline 和 ipympl/widget 模式下运行提供的 Matplotlib 变换示例,然后比较显示的结果和保存的结果。当 widget 模式产生与 inline 模式相同的坐标和注释位置时,该 issue 即完成。

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

描述

Describe the issue

I believe the "transform()" functions of Matplotlib do not behave well in ipympl or widget mode.

Code for reproduction

I simply use the matplotlib example published here:
https://matplotlib.org/3.1.1/tutorials/advanced/transforms_tutorial.html

I copy/paste the code for basic help :

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

x = np.arange(0, 10, 0.005)
y = np.exp(-x/2.) * np.sin(2*np.pi*x)

fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

xdata, ydata = 5, 0
xdisplay, ydisplay = ax.transData.transform_point((xdata, ydata))

bbox = dict(boxstyle="round", fc="0.8")
arrowprops = dict(
    arrowstyle="->",
    connectionstyle="angle,angleA=0,angleB=90,rad=10")

offset = 72
ax.annotate('data = (%.1f, %.1f)' % (xdata, ydata),
            (xdata, ydata), xytext=(-2*offset, offset), textcoords='offset points',
            bbox=bbox, arrowprops=arrowprops)

disp = ax.annotate('display = (%.1f, %.1f)' % (xdisplay, ydisplay),
                   (xdisplay, ydisplay), xytext=(0.5*offset, -offset),
                   xycoords='figure pixels',
                   textcoords='offset points',
                   bbox=bbox, arrowprops=arrowprops)

plt.show()

Actual outcome
I get different results depending on the matplotlib mode :

  • on one side, %matplotlib inline gives the result expected and displayed in the example, as below :
    download
  • on the other side, %matplotlib ipympl or %matplotlib widget give erroneous results, as below :
widget The result is the same if I download with the "floppy-disk" icon of the widget.

Expected outcome

The result with widget or ipympl mode should be the one of inline mode.

Versions

 3.7.7 (default, Mar 26 2020, 10:32:53) 
[Clang 4.0.1 (tags/RELEASE_401/final)]
ipympl version: 0.5.2
jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : 4.7.5
ipython          : 7.16.1
ipykernel        : 5.3.3
jupyter client   : 6.1.6
jupyter lab      : 1.2.6
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.7
traitlets        : 4.3.3
Known nbextensions:
  config dir: /Users/mmyara/.jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /opt/miniconda3/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      plotlywidget/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
    tree section
      ipyparallel/main  enabled 
      - Validating: OK
JupyterLab v1.2.6
Known labextensions:
   app dir: /opt/miniconda3/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.1.0  enabled  OK
        @jupyterlab/toc v2.0.0  enabled  OK
        @lckr/jupyterlab_variableinspector v0.4.0  enabled  OK
        jupyter-matplotlib v0.7.1  enabled  OK
        jupyterlab-plotly v4.9.0  enabled  OK
        plotlywidget v4.9.0  enabled  OK```
主要语言
Jupyter Notebook
星标
1.7k
派生
234
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

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

matplotlib/ipympl 的其他 Issue

查看 matplotlib/ipympl 的全部 Issue

相似的 Issue

更多 Web Dev Issue

把新 issue 发到你的邮箱

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