Skip to content

Font Issue in matplotlib #22

@HumphreyYang

Description

@HumphreyYang

In lectures where we have 'text.usetex': True, we need to add the following headers:

# Configure Matplotlib to use pdfLaTeX and CJKutf8
mpl.rcParams.update({
    'text.usetex': True,
    'text.latex.preamble': r'''
        \usepackage{{CJKutf8}}
        \usepackage{{amsmath}}
    '''
})
# Function to wrap Chinese text in CJK environment
def cjk(text):
    return rf'\begin{{CJK}}{{UTF8}}{{gbsn}}{text}\end{{CJK}}'

Then apply the cjk function to the Chinese character to the figure plotting matplotlib.

Example:
37c0d3c#diff-6d11baeb8df592b6a934e4de8f805cb9986d5b4524917a25c82e3dff8a670180L258-R270

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions