ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 30 Nov 2020 18:50:09 +0100How to eliminate truncated graph arrowheads?https://ask.sagemath.org/question/54450/how-to-eliminate-truncated-graph-arrowheads/The following simple directed graph has truncated arrowheads:
vpos = {'W':(-0.5,0.5),'E':(0.5,0.5),'mW':(-0.5,0),'mE':(0.5,0)}
D1 = DiGraph()
D1.add_edge(('mW','mE','mE-mW'))
D1.add_edge(('W','E','W-E'))
D1.add_edge(('mW','W'))
D1.show(pos=vpos,vertex_size=500,figsize=(2,2))
![image description](https://snipboard.io/FV8Iqy.jpg)
If I change the last statement to:
D1.show(pos=vpos)
I still get truncated horizontal arrows, but less on the vertical.
![image description](https://snipboard.io/P5lAfj.jpg)
Any suggestions for preserving full arrowheads? It looks like the clip limits for arrows are different than those for vertices. Setting `fig_tight=False` has no effect.
Sun, 29 Nov 2020 19:56:09 +0100https://ask.sagemath.org/question/54450/how-to-eliminate-truncated-graph-arrowheads/Answer by dsejas for <p>The following simple directed graph has truncated arrowheads:</p>
<pre><code>vpos = {'W':(-0.5,0.5),'E':(0.5,0.5),'mW':(-0.5,0),'mE':(0.5,0)}
D1 = DiGraph()
D1.add_edge(('mW','mE','mE-mW'))
D1.add_edge(('W','E','W-E'))
D1.add_edge(('mW','W'))
D1.show(pos=vpos,vertex_size=500,figsize=(2,2))
</code></pre>
<p><img alt="image description" src="https://snipboard.io/FV8Iqy.jpg"></p>
<p>If I change the last statement to:</p>
<pre><code>D1.show(pos=vpos)
</code></pre>
<p>I still get truncated horizontal arrows, but less on the vertical.
<img alt="image description" src="https://snipboard.io/P5lAfj.jpg"></p>
<p>Any suggestions for preserving full arrowheads? It looks like the clip limits for arrows are different than those for vertices. Setting <code>fig_tight=False</code> has no effect.</p>
https://ask.sagemath.org/question/54450/how-to-eliminate-truncated-graph-arrowheads/?answer=54474#post-id-54474Hello, @holistone! I am not 100% sure about the reason for this mutilated arrows, but your conjecture that it could be due to the limits for the vertices and edges being different seems correct; at least there is evidence of that (more on that below).
The easiest way to solve your problem is to use the `xmin`, `xmax`, `ymin` and `ymax` arguments for the `show()` method. In your particular case, I can see the positions of your vertices are set by the `vpos` dictionary, which effectively sets the plotting intervals to be $[-0.5,0.5]$ for the $x$-axis and $[0,0.5]$ for the $y$-axis. Thus, we are going to use slightly bigger intervals (for example, $[-0.6,0.6]$ for the $x$-axis and $[-0.1,0.6]$ for the $y$-axis), as in the following code:
vpos = {'W':(-0.5,0.5),'E':(0.5,0.5),'mW':(-0.5,0),'mE':(0.5,0)}
D1 = DiGraph()
D1.add_edge(('mW','mE','mE-mW'))
D1.add_edge(('W','E','W-E'))
D1.add_edge(('mW','W'))
D1.show(pos=vpos,vertex_size=500,figsize=(2,2), xmin=-0.6, xmax=0.6, ymin=-0.1, ymax=0.6)
This is the result:
![image description](/upfiles/16067580593329579.png)
Of course, you can play around with those parameters in order to adjust the layout to your predilection.
**Just a side note:** In some cases, it seems to be a good choice to add a 10% of the total width to the left and the right, and a 10% of the total height to the top and the bottom of the plot.
Now, this is why I believe that your hypothesis about the mutilated edges is true: If you try to replace the last line of the previous code with
D1.show(pos=vpos,vertex_size=500,figsize=(2,2), xmin=-0.4, xmax=0.4, ymin=0.1, ymax=0.4)
which is a way to small plotting area, you get the following image:
![image description](/upfiles/16067583884087256.png)
As you can see, your hypothesis correctly predicts that the vertices are indeed displayed (despite of being too few alloted space), but the edges disappeared because there is not enough "area" to plot them.
I hope this helps!Mon, 30 Nov 2020 18:50:09 +0100https://ask.sagemath.org/question/54450/how-to-eliminate-truncated-graph-arrowheads/?answer=54474#post-id-54474