Created
September 28, 2011 08:58
-
-
Save yamakk/1247411 to your computer and use it in GitHub Desktop.
networkx-1.5(patched)をつかって日本語フォントを使うサンプル
This file contains hidden or 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
#coding:utf-8 | |
""" | |
networkx-1.5にて日本語フォントを使う | |
patch...https://gist.github.com/1247256 | |
$ patch -p1 < nx_pylab.py.patch | |
""" | |
import matplotlib.font_manager | |
import networkx | |
font_path = '/Library/Fonts/Osaka.ttf' | |
font_prop = matplotlib.font_manager.FontProperties(fname=font_path) | |
networkx.set_fontproperties(font_prop) | |
edges= [(u'林檎',2), (u'ミカン',3), (3,2), (1,4), (u'ミカン', 2)] | |
g = networkx.Graph(edges) | |
pos = networkx.spring_layout(g) | |
networkx.draw_networkx_nodes(g, pos, node_size=0.1, node_color='r') | |
networkx.draw_networkx_edges(g, pos, width=0.1) | |
networkx.draw_networkx_labels(g, pos, font_size=12, font_color='k') | |
matplotlib.pyplot.savefig('foo.png', dpi=100) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment