我正在尝试使用matplotlib
生成带有CJK(尤其是日语)标签的绘图。因为CJK可以垂直写入,所以我希望ylabel
以这种方式写入。我在下面找到了一种方法,但是它需要用\n
填充每个字符以创建所需的效果。不过,这是哈基
有没有更好的方法,例如,将每个角色旋转90度
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Make a plot with Japanese labels.
"""
import matplotlib.pyplot as plt
from matplotlib import font_manager as fm
# Set fonts so that labels display correctly.
pathToInstall = '/path/to/fonts'
fontFiles = fm.findSystemFonts(pathToInstall)
fontList = fm.createFontList(fontFiles)
fm.fontManager.ttflist.extend(fontList)
fp = fm.FontProperties()
fp.set_family('Noto Sans Mono CJK JP')
fig = plt.figure()
fig.suptitle('こんにちは、世界さん!', FontProperties=fp) # Fine
plt.xlabel('アイウエオ', FontProperties=fp) # Fine
plt.ylabel(
'あ\nい\nう\nえ\nお', # How can I avoid padding each character with \n?
FontProperties = fp,
rotation = 'horizontal',
verticalalignment = 'center',
horizontalalignment = 'right'
)
plt.show()
目前没有回答
相关问题 更多 >
编程相关推荐