@@ -336,7 +336,7 @@ tree3.draw_svg(
336336
337337(sec_tskit_viz_labelling)=
338338
339- ### Labelling
339+ ### Labelling and annotation
340340
341341Although the default node and mutation labels show unique identifiers, they are't
342342terribly intuituive. The ` node_labels ` and ` mutation_labels ` parameters can be used
@@ -365,10 +365,42 @@ ts_mutated.draw_svg(
365365)
366366```
367367
368+ #### Annotating genome regions
369+
370+ To annotate genomic regions along the X axis of the tree sequence plot, you can pass a
371+ dictionary of ` x_regions ` , mapping ` (start, end) ` tuples to labels. Below we have also
372+ used css to hide all but the first and last x axis tick label to avoid visual clashing,
373+ and hidden all the mutation and node labels by setting them to ` {} ` :
374+
375+ ``` {code-cell} ipython3
376+
377+ x_regions = {(5_000, 12_000): "Gene 1", (21_123, 33_321): "Gene 2"}
378+ hide_internal_x_tick_labels = (
379+ ".x-axis .tick .lab {visibility: hidden}"
380+ ".x-axis .tick:first-of-type .lab, .x-axis .tick:last-of-type .lab {visibility: visible}"
381+ ".x-regions .r1 rect {fill: cyan}" # 2nd region (ID 1) tagged with class="r1"
382+ )
383+ ts_mutated.draw_svg(
384+ size=(1000, 300),
385+ y_axis=True,
386+ y_ticks=range(0, int(ts_mutated.max_time), 1000),
387+ node_labels={},
388+ mutation_labels={},
389+ style=hide_internal_x_tick_labels,
390+ x_regions=x_regions,
391+ )
392+ ```
393+
394+ #### Arbitrary annotation
395+
396+ It is also possible to add arbitrary annotations to the SVG plot, as detailed
397+ in the next section. To locate positions for annotation, see the examples in
398+ {ref}` sec_tskit_viz_svg_plot_internals ` .
399+
368400
369401(sec_tskit_viz_adding_bespoke)=
370402
371- ### Adding bespoke svg
403+ ### Adding bespoke SVG
372404
373405The ` preamble ` option allows arbitrary SVG text to be added at the start of the plot.
374406This can be useful to annotate plots, produce legends, etc. although it requires some
@@ -1921,7 +1953,7 @@ tanglegram(non_ultrametric_ts, node_labels={u:u for u in ts_mutated.samples()},
19211953```
19221954
19231955Here's a larger tanglegram example (Note that if you want to compare two trees in their
1924- own separate tree sequences, you can concatenate them togther using
1956+ own separate tree sequences, you can concatenate them together using
19251957{meth}` .TreeSequence.concatenate ` ).
19261958
19271959``` {code-cell} ipython3
@@ -2191,7 +2223,7 @@ drawinfo = d3arg.draw(
21912223 show_mutations=True,
21922224 label_mutations=True,
21932225)
2194- print(f"Extra styling is possible by targetting CSS at this unique id: {drawinfo.uid}")
2226+ print(f"Extra styling is possible by targetting CSS at this unique id: # {drawinfo.uid}")
21952227```
21962228
21972229For more general graph plots, it can be helpful convert the tree sequence to a
0 commit comments