Ask Your Question
1

How can I add arbitrary text to a Graph object

asked 4 years ago

holistone gravatar image

I have created a Graph image such as shown below

image description

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.

Preview: (hide)

Comments

sage: sage.plot.graphics.Graphics.show? tells you that there is the "title" option. And also about "set_legend_options".

FrédéricC gravatar imageFrédéricC ( 4 years ago )

Thanks, 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))

holistone gravatar imageholistone ( 4 years ago )

Add a node having your text as label, no frame, no edges and manually positioned ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 4 years ago )

The mode would still show as a node with the same format that the other nodes.

holistone gravatar imageholistone ( 4 years ago )

2 Answers

Sort by » oldest newest most voted
3

answered 4 years ago

rburing gravatar image

updated 4 years ago

To 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

Preview: (hide)
link

Comments

1

This works with G.plot() instead of G.show(), and answers my question. Thanks.

holistone gravatar imageholistone ( 4 years ago )

You're welcome. You can accept an answer by clicking the ✅

rburing gravatar imagerburing ( 4 years ago )
2

answered 4 years ago

holistone gravatar image

Thanks to rburing (above) here's a successful example of adding multiple text objects in different colors to a graph: image description

Preview: (hide)
link

Comments

Nice! You can accept your own answer if it best solves the question. This will mark the question as solved.

slelievre gravatar imageslelievre ( 3 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 4 years ago

Seen: 1,542 times

Last updated: Nov 19 '20