matplot程序在运行时提供无响应的窗口

时间:2016-07-07 06:14:39

标签: python python-3.x matplotlib

您会注意到有一堆丢失的代码,它是从菜单中调用的所有游戏的代码。我删除了它,因为它很长,我的问题不需要。我的问题只出现在一个特定的函数display_data上。当我从菜单中调用它时,matplot会在新窗口中打开并立即崩溃。我刚刚设置了下面的基本图表进行测试。有什么想法吗?

import matplotlib.pyplot as plt

def display_data():
    plt.plot([1,2,4],[2,7,9])
    plt.show()

# (6) Save Progress ------------------------------------------------------------

# (7) Load Data ----------------------------------------------------------------

# (8) Quit Game ----------------------------------------------------------------

def quit_game():
    print('\nThank you for playing!')

# Main Menu --------------------------------------------------------------------

def menu():
    calculation_game = print("\nEnter 1 to play 'Calculation'")
    bin_reader = print("Enter 2 to play 'Binary Reader'")
    trifacto = print("Enter 3 to play 'Trifacto'")
    statistics = print("Enter 4 to view your statistics")
    display_data = print("Enter 5 to display data")
    save_game = print("Enter 6 to save your progress")
    load_data = print("Enter 7 to load data")
    quit_game = print("Enter 8 to quit the game")

def main_menu():
    print('Welcome to BrainAge!')
    main_record = []
    user_input = ''
    while user_input != '8':
        menu()
        user_input = input('\nWhat would you like to do? ')
        if user_input == '1':
            calculation_game()
        if user_input == '2':
            binary_reader_game()
        if user_input == '3':
            trifacto_game()
        if user_input == '4':
            display_statistics()
        if user_input == '5':
            display_data()
        if user_input == '8':
            quit_game()

main_menu()

1 个答案:

答案 0 :(得分:5)

我有一个类似的问题,尝试设置这一行

plt.show()

plt.show(block=True)

根据docs,这会覆盖在交互模式下运行matplotlib.pyplot导致的阻塞行为,这种行为在某些环境中会导致问题。我相信这只适用于最新版本的matplotlib。