Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Prototype of plotting matplotlib plots in consecutive processes.
"""Prototype of plotting matplotlib plots in consecutive processes.."""
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from multiprocessing import Pool
# avoid to import pyplot as it'll import (on my machine) backends that fail with multiprocessing.
def do_plot(number):
fig = Figure(figsize=(13, 7))
ax = fig.add_subplot(1, 1, 1)
ax.plot([0, 1, 2, 3], [-1, 1, 0, 2])
if __name__ == '__main__':
with Pool(4) as pool:
for result in [pool.apply_async(do_plot, (id,)) for id in range(10)]:
print("All applied.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment