{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "b6508c70", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from plotnine import *\n", "\n", "df = pd.DataFrame([\n", " { 'lang': 'jp', 'word': 'たこ焼き', 'number': 300 },\n", " { 'lang': 'cn', 'word': '火鍋', 'number': 400 },\n", " { 'lang': 'ko', 'word': '김치', 'number': 200 },\n", "])" ] }, { "cell_type": "markdown", "id": "afd38efa", "metadata": {}, "source": [ "# Displaying East Asian text (Chinese, Japanese, Korean) in plotnine\n", "\n", "When you try to display Chinese, Japanese, or Korean text on a plotnine graphic, you might get an error like this:\n", "\n", "```\n", "/Users/username/.pyenv/versions/3.9.7/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 12383 missing from current font.\n", "/Users/username/.pyenv/versions/3.9.7/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 12371 missing from current font.\n", "/Users/username/.pyenv/versions/3.9.7/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 28988 missing from current font.\n", "```\n", "\n", "This is because many fonts do not support these characters. To display them, you'll need to find a font that works for them.\n", "\n", "## Using Arial Unicode MS\n", "\n", "If we have a dataset of all three languages, `Arial Unicode MS` is a good option that supports characters around the world. We'll use `theme(text=element_text(family='Arial Unicode MS'))` to set all of the text in the graphic to be this font." ] }, { "cell_type": "code", "execution_count": 14, "id": "5a4220df", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | lang | \n", "word | \n", "number | \n", "
---|---|---|---|
0 | \n", "jp | \n", "たこ焼き | \n", "300 | \n", "
1 | \n", "cn | \n", "火鍋 | \n", "400 | \n", "
2 | \n", "ko | \n", "김치 | \n", "200 | \n", "