Ask Your Question
0

Is there a plot function for ordered trees?

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

Peter Luschny gravatar image

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

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)
dyck.pretty_print(type="NE-SE")

But my question is related to:

for c in Compositions(5):
    dyck = dyckpath(c)
    bit = dyck.to_binary_tree()
    print(bit.as_ordered_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()
show(ot.plot())

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

Comments

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 +0100 )edit
1

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 +0100 )edit
1

For a binary tree t, use t.show().

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

1 Answer

Sort by » oldest newest most voted
1

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

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

Stats

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

Seen: 194 times

Last updated: Feb 21