如何在 python 的主菜单中显示 return 之前的图表
how to display plots before return to main menu in python
它显示了我完成循环后的条形图。我如何在条形图再次要求用户输入之前显示条形图?
你必须要求sns
显示剧情:
def menu():
print('Please select one of the following options: \n')
print('1. income per country')
print('2. Marital status')
print('3. Income and education level')
print('4. food analysis')
print('5. Exit')
while True:
try:
option = int(input('Enter your option: '))
if option ==1:
eth = demo_data['country'].nunique()
print('Number of country in the dataset: ', eth)
print('Number of respondents per country: \n')
demo_data['country'].value_counts()
ax = sns.barplot(x = demo_data['Income'], y = demo_data['country'], data = demo_data[demo_data['Age '] > 20]);
ax.plot()
plt.show()
continue
except ValueError:
print("Sorry, I didn't understand that.")
continue
if option <= 0:
print("Sorry, your response must not be negative.")
continue
elif option >5:
print("Sorry, your response must be within the list range.")
continue
else:
break
menu()
这给出了
它显示了我完成循环后的条形图。我如何在条形图再次要求用户输入之前显示条形图?
你必须要求sns
显示剧情:
def menu():
print('Please select one of the following options: \n')
print('1. income per country')
print('2. Marital status')
print('3. Income and education level')
print('4. food analysis')
print('5. Exit')
while True:
try:
option = int(input('Enter your option: '))
if option ==1:
eth = demo_data['country'].nunique()
print('Number of country in the dataset: ', eth)
print('Number of respondents per country: \n')
demo_data['country'].value_counts()
ax = sns.barplot(x = demo_data['Income'], y = demo_data['country'], data = demo_data[demo_data['Age '] > 20]);
ax.plot()
plt.show()
continue
except ValueError:
print("Sorry, I didn't understand that.")
continue
if option <= 0:
print("Sorry, your response must not be negative.")
continue
elif option >5:
print("Sorry, your response must be within the list range.")
continue
else:
break
menu()
这给出了