6
$\begingroup$

Compare following visualizations of two simple graphs in Mathematica 11.2:

K3 Graph[{1 -> 2, 2 -> 3, 3 -> 1}]

enter image description here

Two-edge multi graph Graph[{1 -> 1, 1 -> 1}]

(try also three-edge multi graph Graph[{1 -> 1, 1 -> 1, 1-> 1}]) :

enter image description here

In the second case Mathematica adds unnecessary large margins to all sides. Is there a generic fix for this. I draw many graphs and do not want to adjust this manually.

$\endgroup$
  • 4
    $\begingroup$ noting that PlotRangePadding works with Graph but is ignored in the case of a single-node graph I think this could be labeled as a bug. $\endgroup$ – george2079 May 7 '18 at 13:47
6
$\begingroup$

Another work around, adding a dummy vertex at the same coordinate seems to make things happy.

Graph[{1, 2}, {1 -> 1, 1 -> 1, 1 -> 1}, 
 VertexCoordinates -> {{0, 0}, {0, 0}}]

try also:

Graph[{1 -> 1, 1 -> 1, 1 -> 1}, PlotRange -> 0]
$\endgroup$
6
$\begingroup$

With the help from kglr (deleted comment):

Graphics[Show[Graph[{1 -> 1, 1 -> 1}]][[1]]]

enter image description here

which works by using Show to convert the graph to a Graphics[] object, and then constructing a new graphic using only the primitives and directives, but none of the options.

In this case PlotRangePadding is the option that causes the extra space, so using something like

Graph[{1 -> 1, 1 -> 1, 1 -> 1}, PlotRange -> 0]

or

Show[Graph[{1 -> 1, 1 -> 1}], PlotRangePadding -> None]

will only affect that particular option.

$\endgroup$
0
$\begingroup$

Right-click on the figure and there is a 'Make standard size' function at the bottom. According to the documentation, there seems to be no way to do it programmatically.

$\endgroup$
  • $\begingroup$ Thanks for your answer. Do you know how to do this automatically and not using the mouse? $\endgroup$ – Hotschke May 7 '18 at 13:16
  • $\begingroup$ No according to the document... $\endgroup$ – 梁國淦 May 7 '18 at 13:17
  • 1
    $\begingroup$ This does not do what the OP asks. It resets the figure size. It does not change the plot range or margins. $\endgroup$ – Szabolcs May 7 '18 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.