tkinter.TclError: couldn't connect to display “localhost:18.0”

后端 未结 2 1837
日久生厌
日久生厌 2020-12-30 20:28

I was trying to run a simulation (written in python) in the central server, and when simulation is finished, move saved figure file / saved data file to my local PC, by conn

相关标签:
2条回答
  • 2020-12-30 20:42

    The problem is that you are using an interactive backend which is trying to create figure windows for you, which are failing because you have disconnected the x-server that was available when you started the simulations.

    Change your imports to

    import matplotlib
    matplotlib.use('pdf')
    import matplotlib.pyplot as plt
    
    0 讨论(0)
  • 2020-12-30 20:58

    Generate images without having a window appear (background)

    use a non-interactive backend (see What is a backend?) such as Agg (for PNGs), PDF, SVG or PS. In your figure-generating script, just call the matplotlib.use() directive before importing pylab or pyplot:

    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    
    plt.plot([1,2,3])
    plt.savefig('myfig')
    

    Note: This answer was in short mentioned in a comment. I put it here as an answer to increase visibility since it helped me and I was lucky enough that I decided to read the comments.

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