【发布时间】:2016-07-07 06:14:38
【问题描述】:
您会注意到有一堆缺失的代码,这是针对从菜单中调用的所有游戏的代码。我删除了它,因为它很长而且我的问题不需要。我的问题仅在于特定功能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()
【问题讨论】:
-
它是崩溃还是立即关闭?如果崩溃,请向我们显示错误消息,如果它刚刚关闭,请查找已回答的有关它的问题。
-
它只是打开一个 matplot 窗口并保持白色,并立即停止响应。也没有错误消息,只是硬崩溃。
-
是什么让你认为 matplotlib 崩溃了?对我来说,它确实 崩溃了,但它给出了一个关于后端的错误,这是应该的。如果是这种情况,请尝试在导入之前在一开始就添加
import matplotlib和matplotlib.use('Qt4Agg')或类似内容。有了这个改变,情节就会出现。另外,你为什么要在menu()函数中将所有这些局部变量定义为None?
标签: python python-3.x matplotlib