Colored rectangles to highlight clades
Colored rectangles to highlight clades¶
The easiest way to add colored shapes to a plot is with the Toyplot .rectangle
or .fill()
functions of cartesian axes
objects. For this you simply need to know the coordinates of the area that you wish to fill (See Coordinates). The example below draws two rectangles in the coordinate space and then adds a tree on top of these. You could make more complex polygon shapes using the fill
function (see Toyplot docs). Remember you can use axes.show=True
to see the axes coordinates if you need a reminder of how to set the x and y coordinates of the rectangles.
In [2]:
Copied!
import toytree
import toyplot
# generate a random tree
rtre = toytree.rtree.unittree(20, seed=12345)
# make the canvas and axes
canvas = toyplot.Canvas(width=250, height=400)
axes = canvas.cartesian()
axes.show = True
# draw a rectangle (x1, x2, y1, y2)
axes.rectangle(
-0.75, 0.35, -0.5, 4.5,
opacity=0.25,
color='yellow',
)
# draw a rectangle (x1, x2, y1, y2)
axes.rectangle(
-0.75, 0.35, 4.5, 8.5,
opacity=0.25,
color='magenta',
)
# add tree to the axes
rtre.draw(axes=axes);
import toytree
import toyplot
# generate a random tree
rtre = toytree.rtree.unittree(20, seed=12345)
# make the canvas and axes
canvas = toyplot.Canvas(width=250, height=400)
axes = canvas.cartesian()
axes.show = True
# draw a rectangle (x1, x2, y1, y2)
axes.rectangle(
-0.75, 0.35, -0.5, 4.5,
opacity=0.25,
color='yellow',
)
# draw a rectangle (x1, x2, y1, y2)
axes.rectangle(
-0.75, 0.35, 4.5, 8.5,
opacity=0.25,
color='magenta',
)
# add tree to the axes
rtre.draw(axes=axes);