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?
What is
dyckpath
? There is no such function or method in the Sage library.if you use the console you can switch to
%display unicode_art
For a binary tree
t
, uset.show()
.