Skip to content

Commit

Permalink
Kwargs are passed as pyplot options
Browse files Browse the repository at this point in the history
Getattr allows pyplot to have options dynamically passed to it.
Isinstance processes arguments passed into phylo draw in ways
appropriate to the data types used in them.
  • Loading branch information
nmsutton authored and etal committed Aug 26, 2013
1 parent 5fdb3d8 commit 23ce443
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Bio/Phylo/_utils.py
Expand Up @@ -421,5 +421,15 @@ def draw_clade(clade, x_start, color, lw):
# Also invert the y-axis (origin at the top) # Also invert the y-axis (origin at the top)
# Add a small vertical margin, but avoid including 0 and N+1 on the y axis # Add a small vertical margin, but avoid including 0 and N+1 on the y axis
axes.set_ylim(max(y_posns.itervalues()) + 0.8, 0.2) axes.set_ylim(max(y_posns.itervalues()) + 0.8, 0.2)
""""Keyword arguments passed into this method are accessed as pyplot options. The input format should be:
PyPlotOption=(tuple), PyPlotOption=(tuple, dict), or PyPlotOption=(dict)
For example: Phylo.draw(tree, axhspan=((0.25, 7.75), {'facecolor':'0.5'}), axvline={'x':'0', 'ymin':'0', 'ymax':'1'})"""
for key, value in kwargs.iteritems():
if isinstance(value, dict):
getattr(plt, str(key))(**dict(value))
elif not (isinstance(value[0], tuple)):
getattr(plt, str(key))(*value)
elif (isinstance(value[0], tuple)):
getattr(plt, str(key))(*value[0], **dict(value[1]))
if do_show: if do_show:
plt.show() plt.show()

0 comments on commit 23ce443

Please sign in to comment.