-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Bug report
Bug summary
When plotting with %matplotlib notebook, the canvas gets cropped to a small section in the top left corner.
Code for reproduction
When running the following code:
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.scatter(range(10), range(10))I get the following output in Chrome:
As you can see, the interactive plot is cropped to the top left corner. Inspecting the HTML shows that the height and width are undefined. Therefore, chrome defaults to the size 300 x 150
<canvas
class="mpl-canvas"
style="width: undefinedpx; height: undefinedpx;"
width="NaN"
height="NaN">
</canvas>Closing the tab and rerunning in Firefox, I get no issues.
The shrunk canvas is still interactive (you can still pan the y-axis up and down), but obviously the height and width calculations went awry. I have tried restarting the Jupyter server (and the notebook kernel) and I still get the same result in Chrome.
Note: using %matplotlib inline works fine in Chrome.
To summarize, I only get this issue when I use %matplotlib notebook in Chrome. I don't know if switching to Windows would resolve this problem (I use Ubuntu 20.04).
Versions
I am running Jupyter in a virtual environment managed by Poetry.
% lsb_release -d
Description: Ubuntu 20.04.1 LTS
% poetry run jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.1.1
qtconsole : 4.7.5
ipython : 7.17.0
ipykernel : 5.3.4
jupyter client : 6.1.6
jupyter lab : not installed
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.7
traitlets : 4.3.3
% poetry run python -c 'import matplotlib; print(matplotlib.get_backend())'
TkAgg
% poetry run python -V
Python 3.8.3
% google-chrome --version
Google Chrome 84.0.4147.105
% cat pyproject.toml
...
[tool.poetry.dependencies]
python = "^3.8"
jupyter = "^1.0.0"
pandas = "^1.1.0"
numpy = "^1.19.1"
scipy = "^1.5.2"
networkx = "^2.4"
ipywidgets = "^7.5.1"
matplotlib = "^3.3.0"
sklearn = "^0.0"
...


