0

I have a Tree representing a list, and I would like to plot this list. Unfortunately when I try to listplot my tree mathematica doesn't plot anything.

So, I would like to convert my tree into the list that this tree represents.

What is the function to do it ?

[edit]

to be more explicit here is my problem :

If I have a list, no problem I can plot it. enter image description here

Now imagine that after some manipulation my list has been transformed in a tree, how to put this tree back to the original list to be able to plot it ? enter image description here

As you can see in this second picture, the listplot doesn't work on this tree.

(here it is a simple example, in fact I have a code and at the end my list are trees, but i want to transform them into the list they represent but I don't know how to do it)

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
StarBucK
  • 2,164
  • 1
  • 10
  • 33

2 Answers2

1

Given

u = Range[5];
v = u // TreeForm;

then the original list u is the first (and only) argument of TreeForm, so

ListPlot[v[[1]]]

plot

You should always keep in mind the many of Mathematica's list manipulation functions such as Part and First (which could also be used in this case) work on expressions with any head, not just lists.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
0
u = Range[3];
v = u // TreeForm;

You can also use Apply (@@) to change the Head of v:

foo @@ v

foo[{1, 2, 3}]

Sqrt @@ v

{1, Sqrt[2], Sqrt[3]}

ListPlot @@ v

Mathematica graphics

Or the change the Head (that is, Part 0) directly:

 v[[0]] = ListPlot; v

Mathematica graphics

kglr
  • 394,356
  • 18
  • 477
  • 896