I’m currently trying to plot the data I recieve from an API (Hypixel), by pushing the values into an array and using that array as input for a matplotlib graph. I wanted to make sure it worked, so I made a test program (see below), and sure enough I couldn’t get it to work. I’m completely lost, so I just wanted to ask if any of you knew how to use an array as input for a matplotlib. Thanks :)
import matplotlib.pyplot as plt
import numpy
ab = [1, 2, 3, 4, 5]
ord = [1, 2, 3, 4, 5]
fig, ax = plt.subplots()
ax.plot([ab], [ord])
CodePudding user response:
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy
ab = [1, 2, 3, 4, 5]
ord = [1, 2, 3, 4, 5]
plt.plot(ab,'g*', ord, 'ro')
plt.show()
CodePudding user response:
You may want to look at this post: How to plot in multiple subplots
Where they define number of subplots and then specify which values to be plotted where as you are using subplots.
If you want to plot ab on Y-axis and ord on X-axis:
import matplotlib.pyplot as plt
ab = [1, 2, 3, 4, 5, 6]
ord = [1, 5, 3, 5, 7, 8]
plt.plot(ab, ord)
plt.show()