8000 matplotlib.plot.show always blocks the execution of python script · Issue #12692 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
matplotlib.plot.show always blocks the execution of python script #12692
Closed
@pahome

Description

@pahome

Bug report

matplotlib.plot.show always blocks the execution of python script

Code for reproduction

I try plt.show(block=False) , it failed and appear in a small moment then close itself.

Code:

import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':
    plt.figure(figsize=(10, 10))
    plt.plot(range(5), lw=2, label='Real')
    plt.title('Prediction')
    plt.legend(loc="best")
    plt.show(block=False)
    print("---Plot graph finish---")

I try plt.draw() or interactive mode , it failed, too. Check the code below.

Code:


import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':
    plt.figure(figsize=(10, 10))
    plt.plot(range(5), lw=2, label='Real')
    plt.title('Prediction')
    plt.legend(loc="best")
    plt.draw()
    plt.show()
    print("---Plot graph finish---")

Above will block until I close it.

Code:

import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':
    plt.ion()
    plt.figure(figsize=(10, 10))
    plt.plot(range(5), lw=2, label='Real')
    plt.title('Prediction')
    plt.legend(loc="best")
    plt.draw()
    plt.show()
    print("---Plot graph finish---")

Above will appear nothing, or it appear and disappear very fast.

Expected outcome

I can keep the graph and still execute following code without closing the graph

Matplotlib version

user@ya:~/$ sudo pip freeze | grep matplotlib
matplotlib==2.2.3
user@ya:~/$ sudo pip -V
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
I only execute script in Ubuntu ex: user@ya: python xxx.py
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:    16.04
Codename:   xenial

How to install matplotlib?
pip install

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0