diff --git a/python/tests/data/svg/internal_sample_ts.svg b/python/tests/data/svg/internal_sample_ts.svg index 67553fa8dd..fc9c062b3c 100644 --- a/python/tests/data/svg/internal_sample_ts.svg +++ b/python/tests/data/svg/internal_sample_ts.svg @@ -99,17 +99,17 @@ - + 7 - + 8 - + @@ -227,17 +227,17 @@ - + 7 - + 8 - + @@ -325,12 +325,12 @@ - + 7 - + diff --git a/python/tests/data/svg/ts_multiroot.svg b/python/tests/data/svg/ts_multiroot.svg index 2ee9dc66df..207ca6bf1b 100644 --- a/python/tests/data/svg/ts_multiroot.svg +++ b/python/tests/data/svg/ts_multiroot.svg @@ -253,7 +253,7 @@ - + @@ -272,7 +272,7 @@ 6 - + @@ -404,7 +404,7 @@ - + @@ -418,7 +418,7 @@ 7 - + @@ -466,7 +466,7 @@ - + @@ -480,7 +480,7 @@ 7 - + @@ -512,7 +512,7 @@ - + @@ -536,11 +536,11 @@ 6 - + 1 - + @@ -563,7 +563,7 @@ - + @@ -587,7 +587,7 @@ 6 - + diff --git a/python/tskit/drawing.py b/python/tskit/drawing.py index 76cf46804c..558f913d20 100644 --- a/python/tskit/drawing.py +++ b/python/tskit/drawing.py @@ -1686,19 +1686,18 @@ def assign_x_coordinates(self): # Set up x positions for nodes node_x_coord = {} leaf_x = 0 # First leaf starts at x=1, to give some space between Y axis & leaf - for root in self.tree.roots: - for u in self.tree.nodes(root, order=self.traversal_order): - if self.tree.is_leaf(u): - leaf_x += 1 - node_x_coord[u] = leaf_x + for u in self.tree.nodes(order=self.traversal_order): + if self.tree.is_leaf(u): + leaf_x += 1 + node_x_coord[u] = leaf_x + else: + child_coords = [node_x_coord[c] for c in self.tree.children(u)] + if len(child_coords) == 1: + node_x_coord[u] = child_coords[0] else: - child_coords = [node_x_coord[c] for c in self.tree.children(u)] - if len(child_coords) == 1: - node_x_coord[u] = child_coords[0] - else: - a = min(child_coords) - b = max(child_coords) - node_x_coord[u] = a + (b - a) / 2 + a = min(child_coords) + b = max(child_coords) + node_x_coord[u] = a + (b - a) / 2 # Now rescale to the plot width: leaf_x is the maximum value of the last leaf if len(node_x_coord) > 0: scale = self.plotbox.width / leaf_x