when i use matplotlib in jupyter notebook,it always raise “ matplotlib is currently using a non-GUI backend” error?

后端 未结 10 1376
耶瑟儿~
耶瑟儿~ 2020-11-28 07:40
import matplotlib.pyplot as pl
%matplot inline
def learning_curves(X_train, y_train, X_test, y_test):
\"\"\" Calculates the performance of several models with varyin         


        
相关标签:
10条回答
  • 2020-11-28 08:21

    You don't need the line of "fig.show()". Just remove it. Then it will be no warning message.

    0 讨论(0)
  • 2020-11-28 08:21

    adding %matplotlib inline while importing helps for smooth plots in notebook

    %matplotlib inline
    import matplotlib.pyplot as plt
    

    %matplotlib inline sets the backend of matplotlib to the 'inline' backend: With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.

    0 讨论(0)
  • 2020-11-28 08:23

    I was trying to make 3d clustering similar to Towards Data Science Tutorial. I first thought fig.show() might be correct, but got the same warning... Briefly viewed Matplot3d.. but then I tried plt.show() and it displayed my 3d model exactly as anticipated. I guess it makes sense too. This would be equivalent to your pl.show()

    Using python 3.5 and Jupyter Notebook

    0 讨论(0)
  • 2020-11-28 08:23

    %matplotlib notebook worked for me.

    But the takes time to load and but it is clear.

    0 讨论(0)
  • 2020-11-28 08:24

    If you are using any profiling libraries like pandas_profiling, try commenting out them and execute the code. In my case I was using pandas_profiling to generate a report for a sample train data. commenting out import pandas_profiling helped me solve my issue.

    0 讨论(0)
  • 2020-11-28 08:32

    You can change the backend used by matplotlib by including:

    import matplotlib
    matplotlib.use('TkAgg')
    

    before your line 1 import matplotlib.pyplot as pl, as it must be set first. See this answer for more information.

    (There are other backend options, but changing backend to TkAgg worked for me when I had a similar problem)

    0 讨论(0)
提交回复
热议问题