Matplotlib cannot find basic fonts

后端 未结 10 707
一生所求
一生所求 2020-12-08 00:34

I am using matplotlib version 2.0.0 on Python 3 in a miniconda virtual environment. I am working on a unix scientific computing cluster where I don\'t have root privileges.

相关标签:
10条回答
  • 2020-12-08 00:38

    To get it to work, I had to combine the two current top answers. Here's what worked for me:

    $ sudo apt install msttcorefonts -qq
    $ rm ~/.cache/matplotlib -rf
    
    0 讨论(0)
  • 2020-12-08 00:38

    I actually solved by

    import matplotlib.font_manager

    0 讨论(0)
  • 2020-12-08 00:41

    I was facing a similar issue in a Cloud Datalab docker image running on a gcloud VM. Executing the following fixed the issue for me:

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

    Here is instructions on how to get to the docker image running on the gcloud VM containing the Datalab instance just in case.

    0 讨论(0)
  • 2020-12-08 00:43

    I had this exact same problem on a Vagrant VM running Ubuntu Xenial 64-bit. No matter how many fonts I had already installed, matplotlib was having a problem with the "system" font name "sans-serif". I fixed it by:

    • Stopping Jupyter
    • Installing font-manager: sudo apt install font-manager
    • Cleaning the matplotlib cache directory: rm ~/.cache/matplotlib -fr
    • Restarting Jupyter.

    No more error messages about sans-serif.

    0 讨论(0)
  • 2020-12-08 00:47

    try all the methods above, not work for me.

    my way to solve this is a little dirrent cause I'm using conda on ubuntu server running jupyter

    locate -b '\mpl-data'
    

    find a folder

    /usr/share/matplotlib/mpl-data
    

    then I add the simhei fonts into the font folder in mpl-data . then remove matplotlib fonts cache

    rm -rf ~/.cache/matplotlib
    

    restart jupyter notebook, and it works.

    0 讨论(0)
  • 2020-12-08 00:52

    It took me many hours to finally figure out that I needed to update matplotlib.

    My original version of 3.0.3 (which came with my jupyter-datascience docker image) would give me this error, but updating to 3.1.1 fixed it.

    In the end, my docker script:

    RUN pip install matplotlib==3.1.1
    COPY fonts /usr/share/fonts/truetype/
    RUN fc-cache -fv
    RUN rm /home/jovyan/.cache/matplotlib -rf
    

    is what did it for me.

    0 讨论(0)
提交回复
热议问题