Open 911432 opened 10 months ago
I searched for fonts supported by Google Colab.
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
f = [f.name for f in fm.fontManager.ttflist]
print(f)
['STIXSizeFiveSym', 'DejaVu Sans Mono', 'DejaVu Serif Display', 'STIXNonUnicode', 'STIXSizeThreeSym', 'STIXNonUnicode', 'STIXGeneral', 'cmmi10', 'STIXSizeOneSym', 'STIXSizeFourSym', 'DejaVu Serif', 'DejaVu Serif', 'cmb10', 'DejaVu Sans', 'STIXNonUnicode', 'STIXGeneral', 'STIXSizeOneSym', 'STIXSizeFourSym', 'STIXSizeTwoSym', 'DejaVu Sans Mono', 'STIXGeneral', 'DejaVu Sans', 'DejaVu Sans Mono', 'cmex10', 'DejaVu Serif', 'DejaVu Sans Display', 'STIXSizeThreeSym', 'cmss10', 'DejaVu Sans', 'DejaVu Sans', 'cmsy10', 'STIXSizeTwoSym', 'DejaVu Serif', 'DejaVu Sans Mono', 'cmtt10', 'STIXNonUnicode', 'STIXGeneral', 'cmr10', 'Liberation Serif', 'Liberation Serif', 'Liberation Mono', 'Liberation Sans Narrow', 'Liberation Sans Narrow', 'Liberation Sans Narrow', 'Liberation Sans', 'Humor Sans', 'Liberation Serif', 'Liberation Sans', 'Liberation Sans', 'Liberation Sans Narrow', 'Liberation Sans', 'Liberation Mono', 'Liberation Mono', 'Liberation Mono', 'Liberation Serif']
I wish there was Noto included rather than these fonts.
Thanks for the report. Tracking this internally at b/311413508
Here's an example of installing fonts for use in matplotlib: https://colab.research.google.com/gist/blois/77badd478ad832250202612b6b5c5faa/matplotlib-ja.ipynb
It is inconvenient to have to install fonts for each instance.
Here's an example of installing fonts for use in matplotlib: https://colab.research.google.com/gist/blois/77badd478ad832250202612b6b5c5faa/matplotlib-ja.ipynb
This is helpful but then again I'm not sure why Noto Sans CJK SC nor any other Noto Sans CJK KR can be displayed; Noto Sans CJK JP is only for Japanese. To elaborate I installed the NotoSansCJK.ttc.zip from the noto-website link and the file contains NotoSansCJK.ttc; however after downloading and unzipping in colab and running
import matplotlib.font_manager as fm
font_cache_file = "/root/.cache/matplotlib/fontlist-v330.json" fm_fonts = fm.json_load(font_cache_file)
font_names = [f.name for f in fm.fontManager.ttflist] for font_name in font_names: print(font_name)
Then I find that in the fontlist-v330.json there is only Noto Sans CJK JP, which does not display Chinese.
This worked for me, which is manually defining the path for the .ttf file and then specifying as fontproperties:
import matplotlib.pyplot as plt from matplotlib import font_manager
font_path = 'drive/MyDrive/NotoSansSC-Light.ttf'
font_manager.fontManager.addfont(font_path)
font_properties = font_manager.FontProperties(fname=font_path)
text = "你好,世界!" # Hello, World!
plt.figure() plt.text(0.5, 0.5, text, fontsize=20, ha='center', fontproperties=font_properties)
plt.title("Test Chinese Characters in Matplotlib", fontproperties=font_properties) plt.show()
Describe the current behavior Asian region fonts are not available in Google Colab.
Describe the expected behavior Asian characters appear.
What web browser you are using Chrome
Additional context I wish Google Colab included Noto font.