[matplotlib]我的barplot的x轴上的韩文字母已损坏

时间:2019-01-17 02:43:04

标签: matplotlib

我正在一个文本挖掘项目上,试图从一个具有两个属性-单词,计数的数据框中绘制出一个单词计数图。字是标称值,计数是数值。问题是标称值不是英语,而是韩语。我应用了以下代码,标题和轴都很好,但是标签被打断了(请参考链接)。我该怎么办?

图片:https://user-images.githubusercontent.com/46237445/51291916-345f2c80-1a4c-11e9-87c9-20e406ae0709.png

轴似乎已切断,但是如果仔细看,您会发现所有字母都是正方形。

 # Get modules
from matplotlib import rc
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
import seaborn as sns

# confirm the font
font_list = fm.findSystemFonts(fontpaths=None, fontext='ttf')
print(font_list)

font_path = r"C:\ProgramData\Anaconda3\Lib\site-packages\matplotlib\mpl- 
data\fonts\ttf\NanumMyeongjo-ExtraBold.ttf"
font_path = font_path.replace("'\'", '/')
font_prop = fm.FontProperties(fname = font_path, size = 14)
font_name = font_prop.get_name()
font_name

# Plotting
rc('font', family=font_name)
plt.figure(figsize=(20,10))
plt.title('단어별 빈도수', fontproperties=font_prop)
plt.xlabel("빈도수", fontproperties=font_prop)
plt.ylabel("단어", fontproperties=font_prop)
plt.bar(words, counts)
plt.show()

0 个答案:

没有答案