I am trying to create a set of inputs for an LSTM Neural Network. I wish to create either a list or array (whichever is easiest to work with) from the y co-ordinates of each point on the graph. I have found many tutorials describing how to create a graph from a list/array, but none that describe the other way around. Here is the code I'm working with:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# x-values
x1 = [0, 1, 2, 3, 4, 5]
x2 = [0, 2, 3, 6, 8, 9]
x3 = [0, 3, 5, 8, 9, 10]
# y-values
y1 = [0, 2, 4, 5, 7, 9]
y2 = [0, 3, 4, 7, 8, 9]
y3 = [10, 8, 7, 4, 3, 1]
#Plotting the Line on Graph
plt.plot(x1, y1, color='blue')
plt.plot(x2, y2, color='green')
plt.plot(x3, y3, color='red')
plt.show()
#X-axis label
plt.xlabel("numShot")
#Y-axis label
plt.ylabel("bin_num")
#Graph title
plt.title("GRAPH EXAMPLE")
for n in x1:
plt.plot(x1,y1, color='blue')
plt.xlim(n,n+2)
plt.xlabel("numShot")
plt.ylabel("bin_num")
plt.title("GRAPH EXTRACT")
plt.show()
for n in x2:
plt.plot(x2,y2, color='green')
plt.xlim(n,n+2)
plt.xlabel("numShot")
plt.ylabel("bin_num")
plt.title("GRAPH EXTRACT")
plt.show()
for n in x3:
plt.plot(x3,y3, color='red')
plt.xlim(n,n+2)
plt.xlabel("numShot")
plt.ylabel("bin_num")
plt.title("GRAPH EXTRACT")
plt.show()
Assume these x,y values are not known, they are for example purposes only
The above code creates 3 lines on a single graph, I would like to write a script that would turn the y co-ordinates from the graph back into the list/array as simply as possible, as my coding skill is, er, average at best.
Edit: I've tried adding the following lines to the script as per John's links, however this throws up the following error
line = gca().get_lines()[n]
yd = line.get_ydata()
NameError: name 'gca' is not defined
This confuses me, as I thought gca came with the pyplot import as opposed to being a variable that needs defining.