I want to create 3 line plots and use text boxes and buttons to enter new values to update the graph. I would also like to be able to select the line that I want to update.
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox, Button
import pandas as pd
# Create figure
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2)
# I used pandas to read data from a csv file
# but in this case I will just use dummy values as example
d1 = pd.DataFrame({
"X": [i for i in range(10)],
"Y": [i for i in range(10)]
})
d2 = pd.DataFrame({
"X": [i for i in range(10)],
"Y": [i*2 for i in range(10)]
})
d3 = pd.DataFrame({
"X": [i for i in range(10)],
"Y": [i ** 2 for i in range(10)]
})
# Plot the data
ax.plot(d1["X"], d1["Y"])
ax.plot(d2["X"], d2["Y"])
ax.plot(d3["X"], d3["Y"])
# Show all x ticks
plt.xticks(d1["X"])
# Handles x value text box input
def textx(text):
pass
# Handles y value text box input
def texty(text):
pass
# Handles submit button
def submit(event):
pass
# Text box to input x value
axbox1 = fig.add_axes([0.1, 0.1, 0.5, 0.05])
x_textbox = TextBox(axbox1, "New x value")
x_textbox.on_submit(textx)
# Text box to input y value
axbox2 = fig.add_axes([0.1, 0.05, 0.5, 0.05])
y_textbox = TextBox(axbox2, "New y value")
y_textbox.on_submit(texty)
# Submit button
axbox3 = fig.add_axes([0.81, 0.05, 0.1, 0.075])
submit_button = Button(axbox3, "Submit!")
submit_button.on_clicked(submit)
plt.show()
I can get the graph to update if there is only one text box. For example, the user only inputs a y-value. However, in this case, there are 2 text boxes so each text box needs to wait for the other text box to be filled up and the graph is updated using the submit button. I would also want to be able to select which line I want to update which I am unsure of how to do.