-1

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])
BigBen
  • 46,229
  • 7
  • 24
  • 40
Lalaryk
  • 23
  • 1
  • which kind of plot do you want for your data? – juuso Dec 16 '21 at 14:16
  • 1
    @Lalaryk what's the error? if you want to plot the lines try with `ax.plot(ab, ord)` – Miguel Trejo Dec 16 '21 at 14:17
  • I don’t feel like I have been very clear with my intentions. Basically I want to use arrays so that whenever I want I can just append them, and update the graph so I can get a dynamic graph of sorts – Lalaryk Dec 16 '21 at 14:24

2 Answers2

0
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()
juuso
  • 612
  • 7
  • 26
0

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()
Albin Sidås
  • 321
  • 2
  • 10