5

When I alter the line width used for edges by specifiying the width argument in the networks draw_networkx() function, e.g:

nx.draw_networkx(G, width = 0.03)

the image that results from using

plt.show()

is as expected (in that I can control the edge widths). However, when I use:

plt.savefig('foo.pdf')

the resulting pdf appears to have an unaffected edge width. Saving as png seems to work fine, but I really need a pdf output. I slightly altered a sample code from the networkx website as an example:

import networkx as nx
import matplotlib.pyplot as plt

G=nx.random_geometric_graph(200,0.125)

pos=nx.get_node_attributes(G,'pos')


dmin=1
ncenter=0
for n in pos:
    x,y=pos[n]
    d=(x-0.5)**2+(y-0.5)**2
    if d<dmin:
        ncenter=n
        dmin=d

p=nx.single_source_shortest_path_length(G,ncenter)

plt.figure(figsize=(8,8))
nx.draw_networkx_edges(G,pos,nodelist=[ncenter],alpha=1, width = 0.03)
nx.draw_networkx_nodes(G,pos,nodelist=p.keys(),
                   node_size=80,
                   node_color=p.values(),
                   cmap=plt.cm.Reds_r)

plt.xlim(-0.05,1.05)
plt.ylim(-0.05,1.05)

plt.savefig('random_geometric_graph.pdf')
plt.show()

which results in the images at (pdf on the rhs) http://i49.tinypic.com/2501h6c.jpg

I've tried oping the pdf in Mac's preview, and in adobe, and the problem persists.

Any help/suggestions much appreciated!

Victoria
  • 124
  • 1
  • 4
  • check the `savefig` for options on what is saved out and how (and maybe you can try ps instead if pdf that doesn't work. – deinonychusaur Jan 04 '13 at 15:46
  • possible duplicate: http://stackoverflow.com/questions/7906365/matplotlib-savefig-plots-different-from-show – zenpoy Jan 04 '13 at 15:49
  • I've just found that if I open the pdf file in colorsync utility there's no longer a problem. My matplotlib rc file has identical settings for pdfs png sag etc so I don't think this is the problem as in the link zenpoy references. Does anyone know what may be causing this? It seems to be a problem in viewing the pdf rather than a coding problem now? @deinonychusaur ps results in the same problems when I include the figure in a latex document... – Victoria Jan 04 '13 at 16:20

0 Answers0