0

I have a bit of code that plots multiple lines(numbering in amounts from 0 to 1000), and this runs inside matplotlib animation. Setting the interval for the animation almost becomes irrelevant, because when there are over 100 lines say, a bottleneck appears.

Hence my question, does anyone have a faster way of plotting lines than the method shown below?

import random
import matplotlib.animation as  animation
import matplotlib.pyplot as plt

def plt_metrics():

        fig, (ax1) = plt.subplots()

        def anim(i):

            ax1.clear()

            for k in range(random.randint(250,350)):

                ax1.axhline(y=k, color='black', linewidth = 1)


        ani = animation.FuncAnimation(fig, anim, interval = 500)
        plt.tight_layout()
        plt.show()

plt_metrics()

Thanks.

ajsp
  • 2,512
  • 22
  • 34

0 Answers0