From my understanding matplotlib is a plotting library.
If you want to change the image data (e.g. draw a rectangle on an image), you could use PIL's ImageDraw, OpenCV, or something similar.
Here is PIL's ImageDraw method to draw a rectangle.
Here is one of OpenCV's methods for drawing a rectangle.
Your question asked about Matplotlib, but probably should have just asked about drawing a rectangle on an image.
Here is another question which addresses what I think you wanted to know: Draw a rectangle and a text in it using PIL