Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
patch for enables function draw_networkx_edge_labels to set fontproperties.
--- 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,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment