I wish to utilize the easy plotting feature of Matplotlib to generate some bitmaps as templates or (rather large) convolution kernels.
I followed this post to convert the plot into a Numpy array:
def DrawKernel(x = 0.5, y = 0.5, radius = 0.49, dimension = 256):
'''Make a solid circle and return a numpy array of it'''
DPI = 100
figure, axes = plt.subplots(figsize=(dimension/DPI, dimension/DPI), dpi=DPI)
canvas = FigureCanvas(figure)
Drawing_colored_circle = plt.Circle(( x, y ), radius, color='k')
axes.set_aspect( 1 )
axes.axis("off")
axes.add_artist( Drawing_colored_circle )
canvas.draw()
# Convert figure into an numpy array
img = np.frombuffer(canvas.tostring_rgb(), dtype='uint8')
img = img.reshape(dimension, dimension, 3)
return img
But this seems to show the plot every time it's called (screenshot in Google Colab) :
Since this function will be invoked frequently later, I don't want to see every plot generated with it. Is there a way to let it be generated but not displayed?