I am a beginner in python, so apologies if this is a very basic question. I want legend entries to be shown dependent on input variables. I already searched for a solution, but none of the tutorials on legends seem to cover what I want to achieve. The closest match was this other solution for plt.text which works fine, but does not work for legend entries, see my code example below.
from matplotlib import pyplot as plt
import numpy as np
input_var1 = 4
input_var2 = 3
y1 = np.random.rand(10)
y2 = np.random.rand(10)
x = np.linspace(0, 9, 10)
plt.plot(x, y1)
plt.plot(x, y2)
# Neither
plt.legend("Plot with input = {}".format(input_var1))
# nor
plt.legend(f"Plot with input = {input_var1}")
# works
# but this works:
plt.text(2, 0.2, "Some text with variable = {}".format(input_var1))
plt.show()
What am I missing?

