# Is there a plot function for ordered trees?

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 close merge delete

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

( 2024-02-21 00:41:00 +0200 )edit
1

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

( 2024-02-21 11:07:56 +0200 )edit
1

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

( 2024-02-21 18:00:30 +0200 )edit

Sort by » oldest newest most voted

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

more