'How can I generate matplotlib graphs faster

I am currently doing an experiment with perlin noise, but generating this noise uses a series of plotted markers. Like, a bunch of them, and i need to render a lot of graphs, rendering just 20 takes around 15 minutes. Is there any way to speed up my code?

import matplotlib.pyplot as plt
import math, random, noise, time
import numpy as np

def GeneratePlot(x:int,y:int) -> list:
  pnoiseValues = []
  fig, ax = plt.subplots()
  for X in range(x**2):
    plt.gcf().canvas.flush_events()
    marker = str(random.choice(("o", "s")))
    YPOS = y+noise.pnoise2(X*x/x**2/50, y/x**2/50)
    ax.scatter(X, YPOS, marker=marker)
    pnoiseValues.append(YPOS)
  plt.show()
  return np.array(pnoiseValues)

def GetResults(amount:int,  useDelay=True) -> list:
  results = []
  for i in range(amount):
    print(f"Generating Images & Arrays.. (This may take a while depending on the # of points)")
    time.sleep(.100 if useDelay else 0)
    results.append(GeneratePlot(i**2,i//2**2))
  print(results)
  return results;
GetResults(16)

So I haven’t tried anything yet, since i am new to matplotlib



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source