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

Bug introduced in 10.0 and fixed in 11.2
Problem is due to a BezierCurve bug.

I don't understand why the following does not work:

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


It evaluates fine, but the resulting PDF only seems to show half the loop at vertex 1.

The problem seems to be with EdgeShapeFunction: it displays correctly in Mathematica, but does not export correctly to PDF

• I should probably add that the problem seems to be with EdgeShapeFunction: it displays correctly in Mathematica, but does not export correctly to PDF. – Steve D Oct 6 '14 at 16:49
• I have reported this as a bug to Wolfram Technical Support. A support case with the identification [CASE:1762814] was created. – rhermans Oct 7 '14 at 10:01
• @rhermans and Steve, can either of you (or anyone else reading) confirm that this bug existed in 10.0.0? – Mr.Wizard Oct 14 '14 at 19:19
• @Mr.Wizard, sorry no, I don't have 10.0.0 any more, and Wolfram Technical Support didn't comment further when they replied. 'Replicated and an incident report was forwarded to developers', was pretty much all they said. – rhermans Oct 14 '14 at 19:32
• I can reproduce this bug up through 11.1.1. In 11.2, it is no longer reproducible. – John Fultz Apr 16 '18 at 22:36

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

When actually your graph should look like this

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


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]]


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.

• You can actually fix the problem by removing the EdgeShapeFunction->"Line". – Steve D Oct 6 '14 at 21:45
• On my system (OS X 10.10.4), it doesn't even display correctly in the notebook, so rasterization doesn't help either. I traced the problem back to a BezierCurve bug. – Szabolcs Jul 19 '15 at 9:57

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.

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.

BezierFunction doesn't suffer from the same problem:

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