How to title multiple figures with matplotlib

Introduction

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.

Method

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: plot.png

in conclusion

Thank you for visiting. If you have any suggestions, please leave them in the comments section.

Reference URL

https://openbook4.me/sections/1396 (Viewed: March 2, 2020)

Recommended Posts

How to title multiple figures with matplotlib
[Python] How to draw multiple graphs with Matplotlib
How to use Matplotlib
I want to display multiple images with matplotlib.
How to display images continuously with matplotlib Note
How to return multiple indexes with index method
How to draw a bar graph that summarizes multiple series with matplotlib
[Python] How to draw a line graph with Matplotlib
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
[Python] How to create a 2D histogram with Matplotlib
Animate multiple graphs with matplotlib
Adjust the ratio of multiple figures with the matplotlib gridspec
How to Delete with SQLAlchemy?
[Python] How to draw a scatter plot with Matplotlib
Summary of how to share state with multiple functions
How to embed multiple embeds in one message with Discord.py
How to cancel RT with tweepy
Python: How to use async with
Connect to multiple databases with SQLAlchemy
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to deal with imbalanced data
How to run matplotlib on heroku
How to get started with Scrapy
How to get started with Python
How to deal with DistributionNotFound errors
How to get started with Django
How to Data Augmentation with PyTorch
How to use FTP with Python
How to calculate date with python
How to install mysql-connector with pip3
Easy to draw graphs with matplotlib
How to INNER JOIN with SQLAlchemy
How to install Anaconda with pyenv
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to deal with "You have multiple authentication backends configured ..." (Django)
[Introduction to Matplotlib] Axes 3D animation: I played with 3D Lissajous figures ♬
Two ways to display multiple graphs in one image with matplotlib
How to do arithmetic with Django template
[Blender] How to set shape_key with script
How to suppress display error in matplotlib
Adjust the spacing between figures with Matplotlib
How to get parent id with sqlalchemy
How to add a package with PyCharm
How to draw a graph using Matplotlib
How to install DLIB with 2020 / CUDA enabled
How to use ManyToManyField with Django's Admin
How to use OpenVPN with Ubuntu 18.04.3 LTS
How to use Cmder with PyCharm (Windows)
How to utilize multi-core from multiple languages
How to prevent package updates with apt
How to work with BigQuery in Python
How to use Ass / Alembic with HtoA
How to deal with enum compatibility errors
How to use Japanese with NLTK plot