Created
June 30, 2018 12:24
-
-
Save shijieyao/74c68fbabfdd8d8eb6513d7fbb497e80 to your computer and use it in GitHub Desktop.
Display CJK (here an example of Japanese) in matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# title | |
import matplotlib.pyplot as plt | |
import matplotlib.font_manager | |
fontprop = matplotlib.font_manager.FontProperties(fname="/Users/shijieyao/Library/Fonts/ipam.ttc") | |
plt.plot([1,2,3]) | |
plt.title(u"あいうえお", fontdict = {"fontproperties": fontprop}) | |
plt.show() | |
# annotate | |
import json | |
from collections import OrderedDict | |
import numpy as np | |
import matplotlib | |
import matplotlib.pyplot as plt | |
from sklearn.manifold import TSNE | |
import matplotlib.font_manager | |
fontprop = matplotlib.font_manager.FontProperties(fname="/Users/shijieyao/Library/Fonts/ipam.ttc") | |
vocab = json.load(open('/Users/shijieyao/Downloads/train.in.json'), object_pairs_hook=OrderedDict, encoding='utf-8') | |
lexicon = {} | |
for k,v in vocab.items(): | |
lexicon[v] = k | |
model = np.load('/Users/shijieyao/Downloads/model.npz') | |
X = model['Wemb'] | |
X_embedded = TSNE(n_components=2).fit_transform(X[0:3]) | |
i = 0 | |
for x, y in X_embedded: | |
plt.plot(x,y, 'ro') | |
plt.annotate(xy=(x,y), s=lexicon[i], fontproperties=fontprop) | |
i += 1 | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment