0

As the title says when I try to graph a bunch of graphs, it takes a very long time. For example if I try to plot a silly example like this 10000 times:

n=10000
numbers = []

for i in range(n):
    numbers.append(i)

for i in range(n):
    plt.plot(numbers)

plt.show()

It will take about a minute to show the plot. I know doing this will make it faster

import matplotlib
matplotlib.use('GTKAgg')

But is there any other way to make plotting a bunch of graphs faster? Any suggestions would be much appreciated, thanks!

pepe1
  • 205
  • 1
  • 3
  • 18
  • 1
    Are you trying to plot multiple points on one graph, or are you wanting to creating multiple figures? And have you looked at: https://stackoverflow.com/questions/8955869/why-is-plotting-with-matplotlib-so-slow – Flynn Jul 20 '17 at 15:13

1 Answers1

0

You could do a dynamic plot with plt.ion() example:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
su = fig.add_subplot(111)
su.axis([-1, 1, -1, 1])
plt.ion()  # allows for dynamic plot

for i in range(1000):
    y = np.random.random()
    su.scatter(y**2, y)
    plt.pause(0.4)

while True:
    plt.pause(0.05)

This allows you to see points as they come up on your graph. Is this what you want?

EDIT: Maybe you could try using matplotlib.pyplot's savefig functionality https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.savefig.html
You could have your computer save all of your figures to separate png files. Then you can look at the pictures any time. This method requires minimal time on your part, just let the program run in the background for a bit while it makes the pngs, and you can view them without having to regenerate them at any time.

Alek Westover
  • 244
  • 1
  • 9
  • Nah I just want it to plot all of them faster, I don't know if it's even possible. Thanks though – pepe1 Jul 20 '17 at 14:59