There are many articles about displaying multiple diagrams together in Matplotlib. However, there was not much content to give titles to multiple figures, so I made it an article.
plot.py
#Load the library
import numpy as np
import cv2
import matplotlib.pyplot as plt
#Draw a circle (white, red, green, blue)
white = cv2.circle(np.zeros((200, 200, 3), dtype=np.uint8), (100, 100), 50, (255, 255, 255), thickness = -1)
red = cv2.circle(np.zeros((200, 200, 3), dtype=np.uint8), (100, 100), 50, (0, 0, 255), thickness = -1)
green = cv2.circle(np.zeros((200, 200, 3), dtype=np.uint8), (100, 100), 50, (0, 255, 0), thickness = -1)
blue = cv2.circle(np.zeros((200, 200, 3), dtype=np.uint8), (100, 100), 50, (255, 0, 0), thickness = -1)
#title
titles = ['white', 'red', 'blue', 'green']
#Nesting graphs into lists
graphs = [white, red, blue, green]
#Set display area (row, column)
fig, ax = plt.subplots(2, 2)
#Place the figure
for i in range(0,4):
plt.subplot(2,2,i+1)
plt.title(titles[i], fontsize=20) #Give a title
plt.tick_params(color='white') #Erase memory
plt.tick_params(labelbottom=False, labelleft=False, labelright=False, labeltop=False)
plt.imshow(cv2.cvtColor(graphs[i], cv2.COLOR_BGR2RGB)) #Insert the figure
plt.xlabel('X', fontsize=15) #Give the x-axis a name
plt.ylabel('Y', rotation=0, fontsize=15, labelpad=20) #Give the y-axis a name
#Make sure the figures do not overlap
plt.tight_layout()
#Show figure
plt.show()
The output looks like this:
Thank you for visiting. If you have any suggestions, please leave them in the comments section.
https://openbook4.me/sections/1396 (Viewed: March 2, 2020)
Recommended Posts