Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib + jupter notbook: %matplotlib notebook failed to download figures. #9117

Closed
yuanshuoastro opened this issue Aug 29, 2017 · 12 comments
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@yuanshuoastro
Copy link

Bug report

Bug summary

Using jupter notebook with matplotlib, (%matplotlib notebook), the bottom "Download" under the figure frame does not work.

Code for reproduction

# (in notbook cells:)
import numpy as np

%matplotlib notebook

import matplotlib

import matplotlib.pyplot as plt

plt.figure();
plt.plot(1,1)

Then a frame with bottoms like "Zoom", "Download" appears in the notebook. But I push the "Download", there is not figure out and the errors in the terminal are:
Actual outcome

# If applicable, paste the console output here
#
#
ERROR:tornado.application:Exception in callback <functools.partial object at 0x7ff3ec27d2b8>
Traceback (most recent call last):         
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/tornado/ioloop.py", line 605, in _run_callback
    ret = callback() 
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)             
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/ipykernel/kernelbase.py", line 265, in enter_eventloop
    self.eventloop(self)                   
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/ipykernel/eventloops.py", line 93, in loop_qt4
    kernel.app = get_app_qt4([" "])        
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/IPython/lib/guisupport.py", line 114, in get_app_qt4
    from IPython.external.qt_for_kernel import QtGui                                   
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/IPython/external/qt_for_kernel.py", line 95, in <module>
    QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)                                   
  File "/home/yuanshuo/SYS/anaconda2/lib/python2.7/site-packages/IPython/external/qt_loaders.py", line 372, in load_qt
    api_options))    
ImportError:         
    Could not load requested Qt binding. Please ensure that                            
    PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available,                      
    and only one is imported per session.  

    Currently-imported Qt library:                              None                   
    PyQt4 available (requires QtCore, QtGui, QtSvg):            False                  
    PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): True                   
    PySide >= 1.0.3 installed:                                  False                  
    PySide2 installed:                                          False                  
    Tried to load:                                              ['pyqtdefault']        
                     

Expected outcome
As before, a new web page will open and the figure should be appears in it.

Matplotlib version

  • Operating System: Ubuntu-17.04
  • Matplotlib Version: 2.0.2
  • Python Version:Python 2.7.13 |Anaconda custom (64-bit)
  • Jupyter Version (if applicable):4.3.0
  • Other Libraries: - -
@wjt
Copy link

wjt commented Sep 15, 2017

I see a similar problem when using %matplotlib notebook in the web-based Jupyter Notebook. Clicking the “Download” button opens a new tab with URL about:blank. In the JS console in the new tab, I see:

Not allowed to navigate top frame to data URL: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAAPACAYAAABq3NR5AAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzs3QmYHHWd8PGI4Lnuuq+ssquuIsh64AouIHjrqhziLYqurxv0BVFRV10UREUQEVAQFSSgQgABQUAQwpFwBJJAwhGSQEgCCSQhCQm5SULOmXrr3+kea2b6mKMr/+6pz+d5vo8yXVPzm17Su/ltddewJEmGSZIkSZIkSRqaRR9AkiRJkiRJUn5FH0CSJEmSJElSfkUfQJIkSZIkSVJ+RR9AkiRJkiRJUn5FH0CSJEmSJElSfkUfQJIkSZIkSVJ+RR9AkiRJkiRJUn5FH0CSJEmSJElSfkUfQJIkSZIkSVJ+RR9AkiRJkiRJUn5FH0CSJEmSJElSfkUfQJIkSZIkSVJ+RR9AkiRJkiRJUn5FH0CSJEmSJElSfkUfQJIkSZIkSVJ+RR9AkiRJkiRJUn5FH0CSJEmSJ...AvNOc9zDvWAAAAAACgvtwbAIyEpI3EL8wg2aldlB1nHhlenJF3ccz3hJbLWf+oBgAlrSWejnXov2t6xxsAAAAAANSXewOAbklaT/zMDP7NG0Edl5ryM9rkmWHyXNJF3aMdAPywOe+3vOMNAAAAAADqzb0BQDckrS1uG+0AmaSpYkWs434xoen4hPj6mzHftl3UPdoBwBtM/3b1jjkAAAAAAKg39wYA3ZD0AzM4dofYUUzrYGqHus42dT0gZodk843Z8ef02PwOdWwu5jT5lSnbfOx9Gf3bOCS7/uoPD3nHGwAAAAAA1J97A4BumIG1vIY71DVeXJlRfqHm61BHf5ftmZPRvxNM3lO84w0AAAAAAOrPvQFAN4ocADR1Hix+GJKNQZbHf/XnmTnKFj0AeGfM97qY5B1vAAAAAABQf+4NAAAAAAAAAFAe9wYAAAAAAAAAKI97AwAAAAAAAACUx70BAAAAAAAAAMrzf0w4AHn4pk3FAAAAAElFTkSuQmCC
ondownload
mpl.figure.handle_save
mpl.figure.toolbar_button_onclick
toolbar_event
dispatch @ http://localhost:8888/static/notebook/js/main.min.js?v=f6a3b3448a91a66afde5b12030802956:5
y.handle @ http://localhost:8888/static/notebook/js/main.min.js?v=f6a3b3448a91a66afde5b12030802956:5

I believe this is due to this change in Chrome: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/GbVcuwg_QjM

Some relevant version information:

Python 3.6.2 (default, Aug 11 2017, 11:59:59) 
[GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]

ipython==6.1.0
matplotlib==2.0.2
notebook==5.1.0

@tacaswell
Copy link
Member

It is very odd that IPython is trying to import Qt.

I could not reproduce this with a fresh installation, do you have any configuration on the IPython side that would be trying to use qt?

attn @Carreau

@Carreau
Copy link
Contributor

Carreau commented Sep 16, 2017

Hum I'm unsure why it would start the qt eventloop as well, and can't reproduce here either.
Check the content of your .ipython/

@odedbd
Copy link

odedbd commented Oct 26, 2017

@wjt - I am experiencing the exact same problem. Have you found an easy workaround for this issue?

My current workaround is to close the figure using the X button on the top right and then saving the non-interactive image.

matplotlib==1.5.3
ipython==5.3.0
notebook==4.2.2

@whimian
Copy link

whimian commented Dec 7, 2017

I'm getting the same problem. I'm on windows 10 and using chrome 62. installed everything with conda.

@zaccharieramzi
Copy link

I am still experiencing this issue with nbagg backend. Versions:

Ubuntu 16.04.6
Chrome 72.0.3626.121
Python 3.5.2
jupyter==1.0.0
matplotlib==3.0.3
ipython==7.3.0
notebook==5.7.5

I also have this error in the about:blank page when looking at the chrome developer tools console:

Not allowed to navigate top frame to data URL: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4QAAAH0CAYAAABl8+PTAAAABHNCSVQICAgIfAhkiAAABuhJREFUeJztwQENAAAAwqD3T20ON6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4MsAeskAAZB+zvYAAAAASUVORK5CYII=
ondownload

@kkingstoun
Copy link

I have the same,

windows 10
Chrome 73.0.3683.103
Python 3.7.4
matplotlib 3.0.2

@neilmb
Copy link

neilmb commented Apr 16, 2019

The current download button can't work anymore in Chrome since they removed the ability for pages to open "data:" URIs: https://developers.google.com/web/updates/2017/03/chrome-58-deprecations#remove_content-initiated_top_frame_navigations_to_data_urls

https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js#L34 does exactly what is not allowed by Chrome and calls window.open on the URI of the image object. Unfortunately, that Google Developers page doesn't describe an alternative.

@neilmb
Copy link

neilmb commented Apr 16, 2019

And Firefox specifically allows opening data:image/* URIs still: https://blog.mozilla.org/security/2017/11/27/blocking-top-level-navigations-data-urls-firefox-59/

@ryanmeekins
Copy link

ryanmeekins commented Jul 25, 2019

I've created a button in my Jupyter Notebook to save figures. Is there anyway I could replace the backend function for the Matplotlib's "Download" button with my own save figure function? This would get around having to use Firefox for save figures with the built-in "Download" button.

This is my current button and save function code.

import matplotlib.pyplot as plt
from ipywidgets import widgets
from tkinter import Tk
from tkinter import filedialog as fd

%matplotlib notebook

fig, ax = plt.subplots()
ax.plot([1,2,3],[4,5,6])

button = widgets.Button(description="Save Figure")
display(button)

def save_figure(b):
    Tk().withdraw() # create and withdraw root window
    save_name = fd.asksaveasfilename()
    if save_name:
        fig.savefig(save_name)
button.on_click(save_figure)

@hkayann
Copy link

hkayann commented Mar 3, 2022

This issue still persists. I run Jupyter in Pycharm and I cannot download my figures.

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 5, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Jul 5, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests