the*_*ian 2 python matplotlib python-3.x
您会注意到有一堆丢失的代码,它是从菜单中调用的所有游戏.我删除了它,因为它很长,我的问题不需要.我的问题只是一个特定的功能,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()
Run Code Online (Sandbox Code Playgroud)
我有一个类似的问题,尝试设置这一行
plt.show()
Run Code Online (Sandbox Code Playgroud)
至
plt.show(block=True)
Run Code Online (Sandbox Code Playgroud)
根据文档,这将覆盖matplotlib.pyplot在交互模式下运行导致的阻塞行为,已知这会在某些环境中导致问题.我相信这只适用于最新版本的matplotlib.
| 归档时间: |
|
| 查看次数: |
250 次 |
| 最近记录: |