[Experience] Once and for all, the Chinese display is a big square, not garbled (the most detailed explanation, the picture has the truth)

Problem Description

Insert picture description here
Hello everyone, when we use networkx to display Chinese, we will find that Chinese cannot be displayed.

Solution

  1. Download the font in the attachment;
  2. Execute in jupyter notebook
import matplotlib
print(matplotlib.__path__)

Find the path of matplotlib, and then cd to this path. After cd reaches this path, continue cd, cd to mpl-data / fonts / ttf this path. Then DejaVuSans.ttfthis document we have just replaced under the document, then try to find the font file matplotlib call, really found it. Because matplotlib calls the DejaVuSans.ttf font file by default, as long as you copy a font file you want from Windows and replace DejaVuSans.ttf, there is no problem.

$ mv SimHei.ttf nx.draw(city_graph, city_location, with_labels=True, node_size=10).ttf

Among them, the ttf font used.
In the C: \ Windows \ Fonts path of the Windows system
Insert picture description here
Insert picture description here

Published 42 original articles · praised 28 · visits 4961

Guess you like

Origin blog.csdn.net/KaelCui/article/details/105490052