Jun-10-2022, 03:42 PM
(This post was last modified: Jun-14-2022, 02:47 PM by edencthompson.)
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!
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 graphOutput:
Larz60+ write Jun-10-2022, 04:48 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please refrain from using images to post code.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please refrain from using images to post code.
