2

You'll notice that there is a bunch of missing code, it's for all the games being called from the menu. I removed it because it is long and not needed for my question. My issue is only with a particular function, display_data. When I call it from the menu, matplot opens in a new window and just crashes immediately. I just set up the basic plot below for testing. Any ideas?

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()
3
  • Does it crash or just closes immediately? If crash, show us the error msg, if it just closes, look up the already answered questions about it. Commented Jul 7, 2016 at 6:20
  • It just opens a matplot window and it stays white, and stops responding immediately. No error messages either, just a hard crash. Commented Jul 7, 2016 at 6:24
  • What makes you think that matplotlib crashes? For me it does crash, but it gives an error about the backend, as it should. If this is the case, try adding import matplotlib and matplotlib.use('Qt4Agg') or something similar at the very beginning, before your import. With that change the plot appears as it should. Also, why are you defining all those local variables to None in the menu() function? Commented Jul 9, 2016 at 21:11

2 Answers 2

5

I had a similar problem a while back, try setting this line

plt.show()

to

plt.show(block=True)

According to the docs this overrides the blocking behaviour caused by running matplotlib.pyplot in interactive mode, which is known to cause issues in some environments. I believe this only works for the latest version of matplotlib.

Sign up to request clarification or add additional context in comments.

Comments

0

HOW about

plt.show(block=False)

1 Comment

Considering how the accepted answer says plt.show(block=True), I doubt this. But perhaps you can explain why you think this works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.