Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Poking around a bit in the <code>draw_networkx_labels</code> source, it does indeed come down to a call to <code>ax.text</code> (where ax is a matplotlib axis). So that means you should have as much configurability as you get with any normal MPL text (<a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.text" rel="nofollow noreferrer">docs</a>).</p> <h2>Font names vs font families</h2> <p>As far as I can tell, a font name is an instance of a font family; though because the generic families (eg 'serif') are often given as settings to font family variables. <a href="http://www.w3schools.com/css/css_font.asp" rel="nofollow noreferrer">http://www.w3schools.com/css/css_font.asp</a></p> <p>This has confused me for a while, so please correct me if I'm wrong here.</p> <h1>Finding the full list of fonts</h1> <p>So if you use the technique from <a href="https://stackoverflow.com/a/18821968/1643946">here</a>:</p> <pre><code>avail_font_names = [f.name for f in matplotlib.font_manager.fontManager.ttflist] </code></pre> <p>you get all the (specific) options. Don't know where you find a fuller list than the <a href="http://matplotlib.org/examples/pylab_examples/fonts_demo.html" rel="nofollow noreferrer">font demo</a> for generics.</p> <p>this post shows a method for <a href="https://stackoverflow.com/questions/18962063/matplotlib-setting-title-bold-while-using-times-new-roman/18962217#18962217">searching by name</a>:</p> <pre><code>[i for i in matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf') if 'times' in i.lower()] </code></pre> <h1>Using more than one font for labels in your graph</h1> <p>From the <code>avail_font_names</code> list above, I picked out three for this example; you might have to substitute some of them depending on what you have installed.</p> <pre><code>import matplotlib.pyplot as plt import networkx as nx font_names = ['Sawasdee', 'Gentium Book Basic', 'FreeMono', ] family_names = ['sans-serif', 'serif', 'fantasy', 'monospace'] # Make a graph G = nx.generators.florentine_families_graph() # need some positions for the nodes, so lay it out pos = nx.spring_layout(G) # create some maps for some subgraphs (not elegant way) subgraph_members = [G.nodes()[i:i+3] for i in xrange(0, len(G.nodes()), 3)] plt.figure(1) nx.draw_networkx_nodes(G, pos) for i, nodes in enumerate(subgraph_members): f = font_names[(i % 3)] #f = family_names[(i % 4)] # extract the subgraph g = G.subgraph(subgraph_members[i]) # draw on the labels with different fonts nx.draw_networkx_labels(g, pos, font_family=f, font_size=40) # show the edges too nx.draw_networkx_edges(G, pos) plt.show() </code></pre> <p><img src="https://i.stack.imgur.com/QplAN.png" alt="example figure showing different font labelling"></p> <h2>Resolving the 'Falling back to ...' warnings</h2> <p>Note: if you get errors when of the form "UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to ...", when trying to use fonts even if they do exist, this <a href="http://matplotlib.1069221.n5.nabble.com/Fonts-not-found-td12936.html" rel="nofollow noreferrer">nabble dialog</a> suggests clearing the font cache: (<em>yup, this will irretrievably remove a file</em> but it is auto-generated.)</p> <pre><code>rm ~/.matplotlib/fontList.cache </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload