Matplotlib font size and color

2022/10/26 Paper

1.Font

1.1 Times New Romman fonts

Install fonts on Ubuntu

sudo apt install msttcorefonts -qq
rm ~/.cache/matplotlib -rf

Set font in python

import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"

1.2 Global font size

import matplotlib.pyplot as plt

SMALL_SIZE = 40
MEDIUM_SIZE = 70
BIGGER_SIZE = 120

plt.rcParams["font.family"] = "Times New Roman"
plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title

Seaborn detail in SeabornPlotConfig.md

2. Color

https://matplotlib.org/stable/users/prev_whats_new/dflt_style_changes.html

ColorHex
████████████████ ‘#1f77b4’
████████████████ ‘#ff7f0e’
████████████████ ‘#2ca02c’
████████████████ ‘#d62728’
████████████████ ‘#9467bd’
████████████████ ‘#8c564b’
████████████████ ‘#e377c2’
████████████████ ‘#7f7f7f’
████████████████ ‘#bcbd22’
████████████████ ‘#17becf’

3 Custom table width percentage

Add width control before markdown table

<style>
table th:first-of-type {
    width: 15%;
}
table th:nth-of-type(2) {
    width: 65%;
}
table th:nth-of-type(3) {
    width: 15%;
}
</style>

GNU GPL V3

Search

    Table of Contents