[Python] Matplotlib on Arch Linux (KDE) shows QFont::fromString: Invalid description warnings,...

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Matplotlib on Arch Linux with KDE Plasma 6.3.5 (Wayland). My system's default Qt font is set to "WenQuanYi Micro Hei" (文泉驿微米黑), and it displays correctly in all system applications.

    I have configured my ~/.config/matplotlib/matplotlibrc file to use "WenQuanYi Micro Hei" as the preferred sans-serif font:


    # In ~/.config/matplotlib/matplotlibrc
    font.family: sans-serif
    font.sans-serif: WenQuanYi Micro Hei, DejaVu Sans, ...
    axes.unicode_minus: False


    I've also cleared the Matplotlib font cache (rm -rf ~/.cache/matplotlib).

    When I run a simple Matplotlib script like the one below, the Chinese characters and other text render correctly using "WenQuanYi Micro Hei" (and other specified fonts like Maple Mono if used).

    import matplotlib
    import matplotlib.pyplot as plt

    plt.figure()
    plt.title("你好世界 - Hello World") # Hello World in Chinese and English
    plt.xlabel("测试标签 (Test Label)") # "Test Label" in Chinese and English
    plt.text(0.5, 0.5, "文泉驿微米黑\nPingFang SC\nMaple Mono", ha='center')
    plt.show()

    print(f"Matplotlib config directory: {matplotlib.get_configdir()}")
    print(f"Loaded matplotlibrc: {matplotlib.matplotlib_fname()}")
    print(f"Default font family: {matplotlib.rcParams['font.family']}")
    print(f"Default sans-serif fonts: {matplotlib.rcParams['font.sans-serif']}")


    The output of the print statements confirms that WenQuanYi Micro Hei is the first font in matplotlib.rcParams['font.sans-serif'].

    However, I still get the following warnings in the terminal:

    QFont::fromString: Invalid description '文泉驿微米黑,10,-1,5,400,0,0,0,0,0,0,0,0,0,0,1'
    QFont::fromString: Invalid description 'Maple Mono NF CN SemiBold,12,-1,5,600,0,0,0,0,0,0,0,0,0,0,1,Regular'
    QFont::fromString: Invalid description 'Maple Mono NL NF CN,10,-1,5,400,0,0,0,0,0,0,0,0,0,0,1'
    QFont::fromString: Invalid description 'Maple Mono NL NF CN,10,-1,5,400,0,0,0,0,0,0,0,0,0,0,1'



    My questions are:

    Why do these QFont::fromString: Invalid description warnings appear if the fonts are actually found and render correctly in the plot? Is this a known issue with Matplotlib/Qt on certain Linux setups, especially when system fonts and Matplotlib fonts are configured similarly? Since the rendering is correct, can these warnings be safely ignored, or is there a way to fix/suppress them if they are just "noise"? Here is some system information from fastfetch:

    OS: Arch Linux x86_64
    Host: RedmiBook Pro 15
    Kernel: Linux 6.14.7-zen2-1-zen
    DE: KDE Plasma 6.3.5
    WM: KWin (Wayland)
    Font: 文泉驿微米黑 (10pt) [Qt], 文泉驿微米黑 (10pt) [GTK2/3/4]


    Any insights or suggestions would be greatly appreciated!

    Thanks.

    Continue reading...

Compartilhe esta Página