В данный момент я пытаюсь заставить мой код отобразить все значения, которые пользователь вставил в один график, и распечатать список введенных значений. В документации не очень ясно, как go об этом. Любой совет?
У меня есть эта функция для построения графика:
def g_plot(x,y,title):
"""
Args:
x - the value to be plotted on the x axis, in this case, t, which has an array of independent variables that remains unchanged
y - the value to be plotted against the y axis. In this case, P.
title - to be used to define the titles of the graph, taken from the name of the isotope the user inputted
"""
# Clear previous plot
mplt.clf()
# plot the x and y axis
mplt.plot(x,y)
# Give the plot its titles, using .format(arg) to plot for the name of the isotope the user defined
mplt.title("Decay of {} from t=0 s to t=10s".format(title))
mplt.xlabel("Time /s")
mplt.ylabel("Mass of {} /g".format(title))
# Show the graph
mplt.show()
Эта функция объединяет входные данные пользователя в массив:
# Define function for collecting user input into a numpy array
def collate_u_input(array,iso,hl,amt,et):
"""
Args:
array - the array to append values to
iso, hl, amt, et - user inputs asscoaited with the defined variables
--------------------------------------------------------------------
returns - array with appended values
"""
array.append([iso,hl,amt,et])
return array
График Переменные:
# Define graph variables
# t is an array of independent variables which forms the x-axis. Endpoint is set to true, meaning the bounds of the graph include all values
t = np.linspace(0, 10, 20, endpoint = True)
P = u_input_amt * np.exp(-log(2.0)*(t/u_input_hl))
# Run the function g_plot
g_plot(t,P,u_input_iso)
Затем, после печати графика, я спрашиваю их, хотят ли они выйти. Если они решат выйти, я хочу отобразить все значения, которые они ввели, а также построить все графики этих значений. (Я понимаю, что сейчас все наоборот, печатая значения перед тем, как спросить их, хотят ли они выйти, но я проводил некоторое тестирование)
Функция break_l oop просто зацикливается, пока пользователь не введет y или Затем n обновляет соответствующий bool для выхода или продолжения l oop.
# Print out the values of the isotope_vars array that the user has already calculated
print("\nData so far:")
print('\n'.join([' | '.join(['{:4}'.format(item) for item in row])
for row in isotope_vars]))
# Ask the user if they want to continue
u_input_goahead = input("Plot other data? Y/N")
# Run the break_loop function with the user's decision
goahead = break_loop(u_input_goahead)