![]() |
function accepts infinite parameters and returns a graph with those values - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: function accepts infinite parameters and returns a graph with those values (/thread-37440.html) |
function accepts infinite parameters and returns a graph with those values - edencthompson - Jun-10-2022 Hi y'all, I am trying to create a function that accepts infinite parameters and returns one graph with all parameter values (beta) on it. Currently, the function only returns one graph (good), but it will only graph the first parameter (bad). I'm not sure how to make it graph all lines. I thought my current code would be able to at least graph the first two parameters entered (I know that it wouldn't work for more than that), but it didn't work for two parameters. I guess I don't know how to keep assigning ys to the new parameters (beta). Any help would be great! def beta_graph(*arg): """Accepts infinite parameters- which are the beta values- and returns one graph with all beta values on that graph Note: current code does not do this, but this is the goal""" # assigning counting variable num = 0 length = len(arg) # starting with 0th index of arg tuple beta = arg[num] # creating the figure and axes fig, ax = plt.subplots(1, 1) # generating the x-axis data xs = np.linspace(1, 5, 1000) # assigning constant values v_inf = 2700 # km/s v_0 = 1 # km/s # y-axis data for 0th index ys1 = (v_0 + (v_inf - v_0)*(1 - 1/xs)**beta)/v_inf # plotting 0th index data ax.plot(xs, ys1, label= f'beta = {beta}') ax.text(5, beta, f"{beta}", ha='center') # setting x and y labels ax.set_xlabel('$r / R_*$') ax.set_ylabel('$v(r) / v_{inf}$') while True: # if we've reached the end of the tuple, exit while loop if (num + 1) == length: break # if we haven't reached the end of the tuple, # graph the next beta value else: # y-axis data for next index ys2 = (v_0 + (v_inf - v_0)*(1 - 1/xs)**beta)/v_inf # plotting data ax.plot(xs, ys2, label= f'beta = {beta}') ax.text(5, beta, f"{beta}", ha='center') num = num + 1 beta_graph(0.1, 0.2) # I want them to print on the same graph
|