Can't see the forest for the keys

Python 2, 165 bytes

a=input()
l=max(map(abs,a))
while l+2:s=' _'[l<0];print(s+s.join((([' ^ ','//| \\\\'[x>0::2],'   '][cmp(abs(x),l)],'_|_')[l<0],s*3)[x==0]for x in a)+s).rstrip();l-=1

This is a full program that accepts a list as input. I'm still golfing this horrid mess.


Pyth, 48 bytes

j_.t+sm.i,J\_?d++\|sm?>d0\ \|d\^Jms+Jmkd"/\\"QJd

Try it online: Demonstration or Test Suite

Too lazy for a full explanation. Here just short overview:

I generate the columns first. So the image:

      ^ 
  ^  /|\
 / \ /|\
__|___|__

gets generated as:

["_", "_/", "| ^", "_\", "_", "_//", "|||^", "_\\", "_"]

Notice, that I'm generating only the lower part (everything without the spaces). And I'm also generating them from bottom to top. This is done pretty straightforward.

Then I can use the .t method to append spaces to the strings, so that each string has an equal length. And afterwards I reverse the order and print.


PHP, 231 277 bytes

This challenge has a beautiful output.

$x=fgetcsv(STDIN);for(;$i<2+max(array_map(abs,$x));$i++)for($j=0;$j<count($x);){$_=$x[$j++];$o[$i].=!$i?$_?'__|_':____:(abs($_)>=$i?0>$_?' /|\\':' / \\':($i-1&&abs($_)==$i-1?'  ^ ':'    '));}echo implode("
",array_reverse($o))."_";

Reads a comma separated list (whitespaces are optional) from STDIN:

$ php trees.php
> 1, 2, 0, -4, 6

Ungolfed

$x=fgetcsv(STDIN);
for(;$i<2+max(array_map(abs,$x));$i++)
    for($j=0;$j<count($x);){
        $_=$x[$j++];
        $o[$i] .= !$i ? $_?'__|_':____
                      : (abs($_)>=$i ? 0>$_?' /|\\':' / \\'
                                     : ($i-1&&abs($_)==$i-1 ? '  ^ ' : '    '));
    }
echo implode("\n",array_reverse($o))."_";

Edits

  • Saved 46 bytes. Discarded array initialization, replaced if/else with ternary operators and moved some of the variables around to save a few bytes.