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.Sun, 21 Mar 2021 00:22:19 +0100How can I add arbitrary text to a Graph objecthttps://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/ I have created a Graph image such as shown below
![image description](https://snipboard.io/tyo4dx.jpg)
using the commands:
D = Graph(E)
D.show(pos=posd,**GPopt)
I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.Wed, 18 Nov 2020 20:11:31 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/Comment by FrédéricC for <p>I have created a Graph image such as shown below</p>
<p><img alt="image description" src="https://snipboard.io/tyo4dx.jpg"></p>
<p>using the commands:</p>
<pre><code>D = Graph(E)
D.show(pos=posd,**GPopt)
</code></pre>
<p>I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.</p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54281#post-id-54281`sage: sage.plot.graphics.Graphics.show?` tells you that there is the "title" option. And also about "set_legend_options".Wed, 18 Nov 2020 20:19:30 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54281#post-id-54281Comment by holistone for <p>I have created a Graph image such as shown below</p>
<p><img alt="image description" src="https://snipboard.io/tyo4dx.jpg"></p>
<p>using the commands:</p>
<pre><code>D = Graph(E)
D.show(pos=posd,**GPopt)
</code></pre>
<p>I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.</p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54282#post-id-54282Thanks, that's a good pointer. The "title" and title_pos" options allows me to add a single text label. But what if I would like multiple text options?
Although **.show()** recognizes "show legend", Graph does not accept "legend_label".
I would expect that there is a general way of adding multiple text to a Graph such as
D += text("hello world",(1,1))Wed, 18 Nov 2020 21:38:30 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54282#post-id-54282Comment by holistone for <p>I have created a Graph image such as shown below</p>
<p><img alt="image description" src="https://snipboard.io/tyo4dx.jpg"></p>
<p>using the commands:</p>
<pre><code>D = Graph(E)
D.show(pos=posd,**GPopt)
</code></pre>
<p>I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.</p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54287#post-id-54287The mode would still show as a node with the same format that the other nodes.Wed, 18 Nov 2020 23:15:44 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54287#post-id-54287Comment by Emmanuel Charpentier for <p>I have created a Graph image such as shown below</p>
<p><img alt="image description" src="https://snipboard.io/tyo4dx.jpg"></p>
<p>using the commands:</p>
<pre><code>D = Graph(E)
D.show(pos=posd,**GPopt)
</code></pre>
<p>I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.</p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54283#post-id-54283Add a node having your text as label, no frame, no edges and manually positioned ?Wed, 18 Nov 2020 22:38:43 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54283#post-id-54283Answer by holistone for <p>I have created a Graph image such as shown below</p>
<p><img alt="image description" src="https://snipboard.io/tyo4dx.jpg"></p>
<p>using the commands:</p>
<pre><code>D = Graph(E)
D.show(pos=posd,**GPopt)
</code></pre>
<p>I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.</p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?answer=54291#post-id-54291Thanks to **rburing** (above) here's a successful example of adding multiple text objects in different colors to a graph:
![image description](https://snipboard.io/7USDkR.jpg)Thu, 19 Nov 2020 01:32:52 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?answer=54291#post-id-54291Comment by slelievre for <p>Thanks to <strong>rburing</strong> (above) here's a successful example of adding multiple text objects in different colors to a graph:
<img alt="image description" src="https://snipboard.io/7USDkR.jpg"></p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=56291#post-id-56291Nice! You can accept your own answer if it best solves the question. This will mark the question as solved.Sun, 21 Mar 2021 00:22:19 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=56291#post-id-56291Answer by rburing for <p>I have created a Graph image such as shown below</p>
<p><img alt="image description" src="https://snipboard.io/tyo4dx.jpg"></p>
<p>using the commands:</p>
<pre><code>D = Graph(E)
D.show(pos=posd,**GPopt)
</code></pre>
<p>I would like to add text or a legend (explaining the colors) to the graph, but I have not found a way to add additional text to the Graph object. Suggestions welcome.</p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?answer=54286#post-id-54286To add text to a plot, literally add the result of a call to `text` to the graphics object returned by `plot`:
sage: G = Graph([(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)])
sage: G.plot(pos={ 0: (0,0), 1 : (1,0), 2: (0,1), 3: (1,1) },axes=False) + text("Hello",(0.75, 0.5))
![hello tetrahedron](/upfiles/16057362329404242.png)Wed, 18 Nov 2020 22:49:23 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?answer=54286#post-id-54286Comment by holistone for <p>To add text to a plot, literally add the result of a call to <code>text</code> to the graphics object returned by <code>plot</code>:</p>
<pre><code>sage: G = Graph([(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)])
sage: G.plot(pos={ 0: (0,0), 1 : (1,0), 2: (0,1), 3: (1,1) },axes=False) + text("Hello",(0.75, 0.5))
</code></pre>
<p><img alt="hello tetrahedron" src="/upfiles/16057362329404242.png"></p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54288#post-id-54288This works with **G.plot()** instead of **G.show()**, and answers my question. Thanks.Wed, 18 Nov 2020 23:19:02 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54288#post-id-54288Comment by rburing for <p>To add text to a plot, literally add the result of a call to <code>text</code> to the graphics object returned by <code>plot</code>:</p>
<pre><code>sage: G = Graph([(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)])
sage: G.plot(pos={ 0: (0,0), 1 : (1,0), 2: (0,1), 3: (1,1) },axes=False) + text("Hello",(0.75, 0.5))
</code></pre>
<p><img alt="hello tetrahedron" src="/upfiles/16057362329404242.png"></p>
https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54289#post-id-54289You're welcome. You can accept an answer by clicking the ✅Thu, 19 Nov 2020 00:53:29 +0100https://ask.sagemath.org/question/54280/how-can-i-add-arbitrary-text-to-a-graph-object/?comment=54289#post-id-54289