Skip to content

Instantly share code, notes, and snippets.

@koorukuroo
Forked from yamakk/nx_pylab.py.patch
Created July 18, 2014 12:07
Show Gist options
  • Save koorukuroo/3aae9a3e900e868840ea to your computer and use it in GitHub Desktop.
Save koorukuroo/3aae9a3e900e868840ea to your computer and use it in GitHub Desktop.
--- networkx-1.5/networkx/drawing/nx_pylab.py 2011-06-04 09:45:38.000000000 +0900
+++ nx_pylab.py 2011-10-01 01:48:06.000000000 +0900
@@ -21,7 +21,8 @@
# All rights reserved.
# BSD license.
-__all__ = ['draw',
+__all__ = ['set_fontproperties',
+ 'draw',
'draw_networkx',
'draw_networkx_nodes',
'draw_networkx_edges',
@@ -38,6 +39,13 @@
import networkx as nx
from networkx.drawing.layout import shell_layout,\
circular_layout,spectral_layout,spring_layout,random_layout
+import matplotlib.font_manager
+
+font_path = matplotlib.font_manager.fontManager.defaultFont['ttf']
+fontproperties = matplotlib.font_manager.FontProperties(fname=font_path)
+def set_fontproperties(font):
+ global fontproperties
+ fontproperties = font
def draw(G, pos=None, ax=None, hold=None, **kwds):
"""Draw the graph G with Matplotlib (pylab).
@@ -718,9 +726,10 @@
if not cb.is_string_like(label):
label=str(label) # this will cause "1" and 1 to be labeled the same
t=ax.text(x, y,
- label,
+ unicode(label),
size=font_size,
color=font_color,
+ fontproperties=fontproperties,
family=font_family,
weight=font_weight,
horizontalalignment=horizontalalignment,
@@ -849,9 +858,10 @@
verticalalignment=kwds.get('verticalalignment','center')
t=ax.text(x, y,
- label,
+ unicode(label),
size=font_size,
color=font_color,
+ fontproperties=fontproperties,
family=font_family,
weight=font_weight,
horizontalalignment=horizontalalignment,
@koorukuroo
Copy link
Author

http://pythonkr.github.io/pyconkr-2014/pdf/pyconkr-2014-07_networkx.pdf

import matplotlib.font_manager as fm
fp1 = fm.FontProperties(fname="./NanumGothic.otf")
nx.set_fontproperties(fp1)
G = nx.Graph()
G.add_edge(u'한국어',u'영어')
nx.draw(G, with_labels=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment