Skip to content

A simple 3D scatter plot with %matplotlib notebook is not working #18132

Closed

Description

@chudur-budur

Bug report

Bug summary

A simple 3D scatter plot is not working on jupyter notebook when %matplotlib notebook is enabled. However, it is working for %matplotlib inline

An extremely large, blank window appears that spans beyond the page.

Code for reproduction

%matplotlib notebook

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

A = np.random.random((100,3))
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(A[:,0], A[:,1], A[:,2])
plt.show()

Actual outcome
Fail case

Expected outcome

Expecting a 3D scatter plot of A.

Matplotlib version

  • Operating system: posix Darwin 19.6.0
  • Matplotlib version: 3.3.0
  • Matplotlib backend (print(matplotlib.get_backend())): nbAgg
  • Python version: 3.7.5
  • Jupyter version (if applicable):
    • jupyter core : 4.6.3
    • jupyter-notebook : 6.0.3
    • qtconsole : 4.7.5
    • ipython : 7.16.1
    • 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
  • Other libraries: numpy 1.19.1, scipy 1.5.2

Activity

  1. QuLogic commented on Jul 31, 2020

    @QuLogic
    Member

    What browser are you using?

  2. chudur-budur commented on Jul 31, 2020

    @chudur-budur
    Author

    What browser are you using?

    Google Chrome Version 84.0.4147.105 (Official Build) (64-bit)

  3. QuLogic commented on Jul 31, 2020

    @QuLogic
    Member

    I cannot reproduce in Firefox at all, but in Chromium, it isn't huge. Instead, only about a quarter of the figure is visible, so something weird is definitely going on.

  4. QuLogic commented on Jul 31, 2020

    @QuLogic
    Member

    This seems to be a bug in Chrome's Resize Observer implementation; it defines entry.contentBoxSize, but entry.contentBoxSize.inlineSize is undefined.

    If you go to this page and move the slider, does the text size change, or does only the width of the box get bigger?

    A workaround is:

    diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js
    index f7ef50dab..1aced9e6a 100644
    --- a/lib/matplotlib/backends/web_backend/js/mpl.js                                  
    +++ b/lib/matplotlib/backends/web_backend/js/mpl.js
    @@ -171,7 +171,7 @@ mpl.figure.prototype._init_canvas = function () {
             for (var i = 0; i < nentries; i++) {                     
                 var entry = entries[i];             
                 var width, height;                  
    -            if (entry.contentBoxSize) {         
    +            if (entry.contentBoxSize && entry.contentBoxSize.inlineSize !== undefined && entry.contentBoxSize.blockSize !== undefined) {
                     width = entry.contentBoxSize.inlineSize;                                                                                 
                     height = entry.contentBoxSize.blockSize;                                                                               
                 } else {                                                                                                                   
  5. chudur-budur commented on Jul 31, 2020

    @chudur-budur
    Author

    This seems to be a bug in Chrome's Resize Observer implementation; it defines entry.contentBoxSize, but entry.contentBoxSize.inlineSize is undefined.

    If you go to this page and move the slider, does the text size change, or does only the width of the box get bigger?

    A workaround is:

    diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js
    index f7ef50dab..1aced9e6a 100644
    --- a/lib/matplotlib/backends/web_backend/js/mpl.js                                  
    +++ b/lib/matplotlib/backends/web_backend/js/mpl.js
    @@ -171,7 +171,7 @@ mpl.figure.prototype._init_canvas = function () {
             for (var i = 0; i < nentries; i++) {                     
                 var entry = entries[i];             
                 var width, height;                  
    -            if (entry.contentBoxSize) {         
    +            if (entry.contentBoxSize && entry.contentBoxSize.inlineSize !== undefined && entry.contentBoxSize.blockSize !== undefined) {
                     width = entry.contentBoxSize.inlineSize;                                                                                 
                     height = entry.contentBoxSize.blockSize;                                                                               
                 } else {                                                                                                                   

    Yes, that slider page is working on my chrome. I will test mpl.js with your modification as soon as possible.

  6. QuLogic commented on Aug 1, 2020

    @QuLogic
    Member

    Yes, that slider page is working on my chrome.

    Do you mean the font gets bigger? It doesn't work for me.

  7. added this to the v3.3.1 milestone on Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions