Self-loops in Graph may not display correctly or export correctly to PDF (due to BezierCurve problem)

I can reproduce your problem (Win7 64, M10.0.1). Same problem if you try with PDF or EPS format.

Graph with bug

When actually your graph should look like this

Graph[{1 <-> 1, 1 <-> 2}, EdgeShapeFunction -> "Line",  EdgeStyle -> {Black}, VertexStyle -> Black, VertexSize -> .05]

Mathematica graphics

It looks like this is a bug, but there is an easy way around if you can afford to have a raster image instead of a vector. The graph can be transformed into a bitmap using Rasterize

Export["graph.pdf", 
 Rasterize[
  Graph[{1 <-> 1, 1 <-> 2}, EdgeShapeFunction -> "Line", 
   EdgeStyle -> {Black}, VertexStyle -> Black, VertexSize -> .05], 
  ImageSize -> 2^10]]

Graph rasterized

Until this is fixed if you need vector format, you can use SVG, which works fine.

EDIT:

or, you can remove the option EdgeShapeFunction->"Line" as pointed out by @Steve_D, i.e yourself. Still, this is a bug.

enter image description here


On my system (OS X 10.10.4) it doesn't even display correctly on-screen. This means that rasterization doesn't help.

I can confirm the problem in 10.0.2, 10.1.0 and 10.2.0. The problem doesn't exist in 9.0.1.

enter image description here

We can trace back this problem to a BezierCurve bug.

gr = 
  Show@Graph[{1 <-> 1, 1 <-> 2}, EdgeShapeFunction -> "Line", 
    EdgeStyle -> {Black}, VertexStyle -> Black, VertexSize -> .05];

bc = First@Cases[gr, _BezierCurve, Infinity]
(* BezierCurve[{{1., 0.}, {1.08848, 0.190784}, {1.28736, 0.24718}, {1.41453, 0.188223}, {1.41453, -0.188223}, {1.28736, -0.24718}, {1.08848, -0.190784}, {1., 0.}}, SplineDegree -> 7] *)

Graphics[{bc, Red, PointSize[Large], Point[pts], Black, Dashed, Line[pts]}]

Note that only half of the curve is displayed. This only happens with SplineDegree -> 7 in this case.

Mathematica graphics

BezierFunction doesn't suffer from the same problem:

ParametricPlot[BezierFunction[pts, SplineDegree -> 7][t] // Evaluate, {t, 0, 1}]

Mathematica graphics