Ask Your Question

Is there a plot function for ordered trees?

asked 2024-02-20 22:14:03 +0200

Peter Luschny gravatar image

updated 2024-02-21 16:28:44 +0200

My workflow is:

# Integer compositions -> Dyck paths
def dyckpath(c):
    return DyckWord(sum([[1]*a + [0]*a for a in c], []))

You can print a dyckpath with

dyck = dyckpath(c)

But my question is related to:

for c in Compositions(5):
    dyck = dyckpath(c)
    bit = dyck.to_binary_tree()

This gives me something which looks like

[[[[], []], []], [[[], []], [[[], []], []]]]

Is there a plot function that knows this format and transforms it into a nice plot?

Edit: Taking John's answer as a starting point I tried:

ot = bit.as_ordered_tree()

This works, but note that you have to use additionally the function 'show'.

According to this logic I would now expect that show(bit.plot()) would also work. Unfortunately, this is not the case. Then you get the error message: 'BinaryTrees_all_with_category.element_class' object has no attribute 'plot'. What can I do in this case?

edit retag flag offensive close merge delete


What is dyckpath? There is no such function or method in the Sage library.

John Palmieri gravatar imageJohn Palmieri ( 2024-02-21 00:41:00 +0200 )edit

if you use the console you can switch to %display unicode_art

FrédéricC gravatar imageFrédéricC ( 2024-02-21 11:07:56 +0200 )edit

For a binary tree t, use

John Palmieri gravatar imageJohn Palmieri ( 2024-02-21 18:00:30 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2024-02-21 00:42:52 +0200

If T is an ordered tree, then there is a method T.plot() that plots T.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2024-02-20 22:14:03 +0200

Seen: 140 times

Last updated: Feb 21