matplot 程序运行时窗口无响应

问题描述 投票:0回答:2

您会注意到有一堆缺失的代码,它适用于从菜单中调用的所有游戏。我删除了它,因为它很长并且对于我的问题来说不需要。我的问题仅与特定功能有关,

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()
python python-3.x matplotlib
2个回答
5
投票

我不久前也遇到过类似的问题,尝试设置这条线

plt.show()

plt.show(block=True)

根据 docs,这会覆盖在交互模式下运行

matplotlib.pyplot
导致的阻塞行为,已知这会在某些环境中导致问题。我相信这只适用于最新版本的 matplotlib。


0
投票

怎么样

plt.show(block=False)
© www.soinside.com 2019 - 2024. All rights reserved.