Function Repository Resource:

PolarTreemapPlot

Source Notebook

Plot a polar tree map of a given nested list

Contributed by: Michael Sollami

ResourceFunction["PolarTreemapPlot"][list]

generates a polar treemap plot of a tree-like structure list.

Details and Options

The first argument list of ResourceFunction["PolarTreemapPlot"] is typically a list of arbitrarily nested and ragged numbers.
ResourceFunction["PolarTreemapPlot"] take the following options:
BackgroundWhitespecify what background color to use
ColorFunctionAutomaticapplies a given color function f[path,area,{rad1,rad2}] to the arc sectors
ImageSize500specify the size of the resulting graphic
"TooltipFunction"Automaticapplies a tooltip function f[path,area,{rad1,rad2}] to the arc sectors
"SortSectors"Truewhether to leave arc sectors in their original ordering or sort by area

Examples

Basic Examples (1) 

Plot simple polar tree map:

In[1]:=
ResourceFunction["PolarTreemapPlot"][{1, 2, {1, 3, 2}}, "SortSectors" -> True, ImageSize -> 150]
Out[1]=

Scope (4) 

Compare a polar tree map to other tree visualizations:

In[2]:=
t = {{1, {1, 2}, 3, 4}};
ResourceFunction[
  "PrettyGrid"][{{"PolarTreemapPlot", ResourceFunction["PolarTreemapPlot"][t, ImageSize -> 150]}, {"ExpressionGraph", ExpressionGraph[t, VertexLabels -> Automatic, ImageSize -> 150]}, {"ExpressionViewer", ResourceFunction["ExpressionViewer"][t]}}\[Transpose], Spacings -> {2, 2}]
Out[3]=

Plot random polar tree maps of varying depths:

In[4]:=
trees = {{1, 1}, {{1, 2}, 3, 4}, {1, {{1, 1}, {1, 1, 1}}}, {1, 2, 6, 4, 8, 2, 1, {1, {1, {2, 1}}}}, {1, {1, 2, {1, {{1, 1, 1, 1, 1, 2, 5}, 1, 2, 1, 1}, 2}}, 5, {1, {1, {2, 1}}}}};
Row[Labeled[
    ResourceFunction["PolarTreemapPlot"][#, ImageSize -> 50*Depth[#]/2], Row@{"Depth ", Depth[#]}] & /@ trees, Spacer[20]]
Out[5]=

Tooltips (displayed by default) show both the path from the root to the selected node and the area of its subtree:

In[6]:=
tree = {{1, 1}, {{1, 2}, 3, 4}, {1, {{1, 1}, {1, 1, 1}}}, {1, 2, 1, {1, {1, {2, 1}}}}};
In[7]:=
ResourceFunction["PolarTreemapPlot"][tree, Background -> Black, ImageSize -> 250, "SortSectors" -> False, ColorFunction -> (ColorData["NeonColors"][#2/Depth[tree]] &)]
Out[7]=

Set the resultant image size and use a custom color function:

In[8]:=
cf = (Which[#2 < 1, Black, #2 < 2, Gray, True, ColorData["DeepSeaColors"][
      			Rescale[Mean[#3], {0, 2 \[Pi]}, {0, 1}]]] &);
ResourceFunction[
 "PolarTreemapPlot"][{{1, 1}, {{1, {1, 1}, {{1, 2}, 3, 4}, {1, {{1, 1}, {1, 1, 1}}}, {1, 2, 1, {1, {1, {2, 1}}}}}, 3, 4}, {1, {{1, 1}, {1, {1, {{1, 1}, {1, 1, 1}}}, 1}}}, {1, 2, 1, {1, {{1, {{1, 1}, {1, 1, 1}}}, {2, 1}}}}}, ImageSize -> 250, ColorFunction -> cf, Background -> None]
Out[7]=

Options (3) 

Set a custom tooltip function:

In[9]:=
tf = TextGrid[{{"path", #1}, {"area", #2}, {"arc", #3}}, Dividers -> All] &;
ResourceFunction["PolarTreemapPlot"][{1, 2, {1, 3, 2}}, "TooltipFunction" -> tf, ImageSize -> 200]
Out[7]=

By default, all arc sectors are sorted by value, i.e. area:

In[10]:=
Manipulate[
 ResourceFunction["PolarTreemapPlot"][{1, 3, 2, {1, 3, 2}}, "SortSectors" -> sort, ImageSize -> 200], {sort, {True, False}}]
Out[10]=

When unsorted, arc sectors may be ordered differently:


Set the Background color and ImageSize of the plot:

In[11]:=
tree = {2, 2, {{1, 1}, 1}, 2};
ResourceFunction["PolarTreemapPlot"][tree, ImageSize -> {200, 100}, Background -> None]
Out[7]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 21 April 2020

Related Resources

License Information