Skip to content
Browse files

Kwargs are passed as pyplot options

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...
1 parent 5fdb3d8 commit 23ce443a5891e9b78760cb245b67cdf16c7026f0 @nmsutton nmsutton committed with etal Apr 26, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 Bio/Phylo/_utils.py
View
10 Bio/Phylo/_utils.py
@@ -421,5 +421,15 @@ def draw_clade(clade, x_start, color, lw):
# 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
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:
plt.show()

0 comments on commit 23ce443

Please sign in to comment.
Something went wrong with that request. Please try again.