“UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.” when plotting figure with pyplot on Pycharm

前端 未结 14 832
梦谈多话
梦谈多话 2020-12-22 18:33

I am trying to plot a simple graph using pyplot, e.g.:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()

but the figure

14条回答
  •  Happy的楠姐
    2020-12-22 19:10

    This worked with R reticulate. Found it here.

    1: matplotlib.use( 'tkagg' ) or 2: matplotlib$use( 'tkagg' )

    For example:

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib import style
    
    import matplotlib
    matplotlib.use( 'tkagg' )
    
    
    style.use("ggplot")
    from sklearn import svm
    
    x = [1, 5, 1.5, 8, 1, 9]
    y = [2, 8, 1.8, 8, 0.6, 11]
    
    plt.scatter(x,y)
    plt.show()
    

提交回复
热议问题