Skip to content

Instantly share code, notes, and snippets.

@yamakk
Created September 28, 2011 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamakk/1247411 to your computer and use it in GitHub Desktop.
Save yamakk/1247411 to your computer and use it in GitHub Desktop.
networkx-1.5(patched)をつかって日本語フォントを使うサンプル
#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