0

I am trying to find a set of parameters to fit some data. I want to be able to change the parameters and plot all the graphs on one plot. This is some simple example code.

import numpy as np
import matplotlib.pyplot as plt

vel=10
r=2
array1=np.linspace(1,100,100)
array2=(array1**2)/(r*vel**2)

Now I can plot array2 vs array1. But I want to now vary my vel and r parameters and plot all those plots on one plot. For example I want to change it to r=3 and then vary vel from 1-10 and plot all 10 of those plots. Then change it to r=4 and vary vel from 1-10 and plot all 10 of those and so on all the way to r=10.

What is the most efficient way of going about doing this?

1 Answer 1

1

Thats probably way too many lines. You could likely gain the same insight from a much smaller subset. But this will do what you asked.

fig, ax = plt.subplots()
arr1 = np.linspace(1, 100, 100)
for r in range(2, 11):
    for vel in range(1, 11):
        arr2 = (arr1 ** 2) / (r * vel ** 2)
        ax.plot(arr1, arr2)
plt.show()

You can get the same idea with fewer lines with the following:

fig, ax = plt.subplots()
arr1 = np.linspace(1, 100, 100)
for r in range(2, 11, 3):
    for vel in range(1, 11, 5):
        arr2 = (arr1 ** 2) / (r * vel ** 2)
        ax.plot(arr1, arr2)
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.