Get the list of figures in matplotlib

Pyplot has get_fignums method that returns a list of figure numbers. This should do what you want: import matplotlib.pyplot as plt import numpy as np x = np.arange(100) y = -x plt.figure() plt.plot(x) plt.figure() plt.plot(y) for i in plt.get_fignums(): plt.figure(i) plt.savefig(‘figure%d.png’ % i)

How to prevent x-axis labels from overlapping

I think you’re confused on a few points about how matplotlib handles dates. You’re not actually plotting dates, at the moment. You’re plotting things on the x-axis with [0,1,2,…] and then manually labeling every point with a string representation of the date. Matplotlib will automatically position ticks. However, you’re over-riding matplotlib’s tick positioning functionality (Using …

Read more

How to read an image in Python OpenCV

If you are trying to display OpenCV image using matplotlib, use the code below. import numpy as np import cv2 import matplotlib.pyplot as plt %matplotlib inline # if you are running this code in Jupyter notebook # reads image ‘opencv-logo.png’ as grayscale img = cv2.imread(‘/path_to_image/opencv-logo.png’, 0) plt.imshow(img, cmap=’gray’)

How do you directly overlay a scatter plot on top of a jpg image in matplotlib / Python?

The pyplot.scatter() function was tailor made for this reason: import matplotlib.pyplot as plt im = plt.imread(image_name) implot = plt.imshow(im) # put a blue dot at (10, 20) plt.scatter([10], [20]) # put a red dot, size 40, at 2 locations: plt.scatter(x=[30, 40], y=[50, 60], c=”r”, s=40) plt.show() See the documentation for more info.

Using plt.imshow() to display multiple images

To display the multiple images use subplot() plt.figure() #subplot(r,c) provide the no. of rows and columns f, axarr = plt.subplots(4,1) # use the created array to output your multiple images. In this case I have stacked 4 images vertically axarr[0].imshow(v_slice[0]) axarr[1].imshow(v_slice[1]) axarr[2].imshow(v_slice[2]) axarr[3].imshow(v_slice[3])