[PYTHON] Increase the font size of the graph with matplotlib

demo

Before After
sc0.png sc1.png

Method (1) Specify the font size separately

Each graph element is the character size of the numerical value by giving a numerical value to the keyword argument fontsize. However, for the font size of the scale, specify plt.tick_params (labelsize = 18).

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 10, 0.1)
s = np.sin(x)
c = np.cos(x)

plt.plot(x, s, "r", label="sin")
plt.plot(x, c, "k", label="cos")
plt.title("Title", fontsize=18)
plt.xlabel("xlabel", fontsize=18)
plt.ylabel("ylabel", fontsize=18)
plt.legend(fontsize=18)
plt.tick_params(labelsize=18)

plt.savefig("output.png ")

Method (2) Specify the font size collectively

plt.rcParams["font.size"] = 18

With, you can change the font size of all graph elements at once. The default font size is 12. (Thanks to Tsutomu-KKE @ github, 2016/01/26)

bonus

Adjusting the graph position

A part of the graph may protrude from the output image due to the side effect of increasing the font size of each graph element. Therefore,

plt.tight_layout()

By adding, the position and size of the graph are automatically adjusted, and the protrusion from the output image can be suppressed.

Before correction Revised
1.png 2.png

For copy

plt.rcParams["font.size"] = 18
plt.tight_layout()

reference

Introduction to matplotlib-Apples are out http://bicycle1885.hatenablog.com/entry/2014/02/14/023734

Tight Layout guide — Matplotlib 1.5.1 documentation http://matplotlib.org/users/tight_layout_guide.html

Recommended Posts

Increase the font size of the graph with matplotlib
Align the size of the colorbar with matplotlib
The basis of graph theory with matplotlib animation
Increase the UI size of MyPaint
About the size of matplotlib points
[Python] Set the graph range with matplotlib
[pyqtgraph] Set the size ratio of the graph
[Python] limit axis of 3D graph with Matplotlib
Change the font size of the legend in df.plot
Band graph with matplotlib
Visualize the behavior of the sorting algorithm with matplotlib
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
Add information to the bottom of the figure with Matplotlib
Omit the decimal point of the graph scale in matplotlib
Display the graph while changing the parameters with PySimpleGUI + Matplotlib
Adjust the ratio of multiple figures with the matplotlib gridspec
Graph Excel data with matplotlib (1)
Graph drawing method with matplotlib
Graph Excel data with matplotlib (2)
Change the style of matplotlib
Connected components of the graph
Reformat the timeline of the pandas time series plot with matplotlib
Let's visualize the number of people infected with coronavirus with matplotlib
I wrote the basic operation of matplotlib with Jupyter Lab
How to plot a lot of legends by changing the color of the graph continuously with matplotlib
[Python] font family and font with matplotlib
Draw a loose graph with matplotlib
Output the call graph with PyCallGraph
Easy Japanese font setting with matplotlib
Unravel the mystery of matplotlib specgram
Read the coordinates of the plot on the graph with Python-matplotlib (super beginner)
[Statistics] Grasp the image of the central limit theorem with a graph
Later expand the disk size of Fedora CoreOS deployed with OVA
Count the maximum concatenated part of a random graph with NetworkX
I tried to expand the size of the logical volume with LVM
[Python] How to specify the window display position and size of matplotlib
Adjust the spacing between figures with Matplotlib
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Adjust the bin width crisply and neatly with the histogram of matplotlib and seaborn
(Matplotlib) I want to draw a graph with a size specified in pixels
Check the existence of the file with python
Display the graph of tensorBoard on jupyter
Set the xticklabels color individually with matplotlib
The third night of the loop with for
Read the graph image with OpenCV and get the coordinates of the final point of the graph
Graph trigonometric functions with numpy and matplotlib
Tips: Comparison of the size of three values
Display markers above the border with matplotlib
The second night of the loop with for
Check the file size with du -sh *
Match the colorbar to the figure with matplotlib
Count the number of characters with echo
Make common settings with subplot of matplotlib
Create a graph with borders removed with matplotlib
Paste a link to the data point of the graph created by jupyterlab & matplotlib
Get the stock price of a Japanese company with Python and make a graph
Draw a flat surface with a matplotlib 3d graph
The story of doing deep learning with TPU
Note: Prepare the environment of CmdStanPy with docker
Prepare the execution environment of Python3 with Docker
About the X-axis notation of Matplotlib bar graphs