Plotting multiple lines using multiprocessing

Is it possible to plot multiple lines on same subplot or axes using multiprocessing ?
I am trying to achieve some performance improvement. I tried using ProcessPoolExecutor, but it only calls my plotting function once and even than the plot is not displayed. I tried something like this:-

def plot (X,y):


with ProcessPoolExecutor(max_workers=4) as ex:, X_arr,y_arr)

Matplotlib is not thread-safe, and certainly does not coalesce figures from multiple processes. You should ensure that all drawing on a single figure occurs in single thread/process.

1 Like

Sure, Though matplotlib is not thread safe, but for experimental basis I tried to coalesce multiple plotting on a single axes using threads(ThreadPoolExecutor). Though it worked but gave up for two reasons

  1. Matplotlib is not thread safe.
  2. Threads are not good for cpu intensive work in python.

Any other recommendations on how to increase performance of plotting in matplotlib. ?

Thank you so much

If you need to plot a lot of lines, you can usually get huge speedups by making a LineCollection rather than calling plt.plot repeatedly.

Sure , will give this a try ,
Thanks :slight_smile: