Hi,
SciPy (and NumPy) docstrings are written with a special kind of mark up:
For example, the docstring for the russellrao distance function looks like this:
'\n Computes the Russell-Rao dissimilarity between two boolean 1-D arrays.\n\n The Russell-Rao dissimilarity between two boolean 1-D arrays, u
and\n v
, is defined as\n\n … math::\n\n \frac{n - c_{TT}}\n {n}\n\n where :math:c_{ij}
is the number of occurrences of\n :math:\\mathtt{u[k]} = i
and :math:\\mathtt{v[k]} = j
for\n :math:k < n
.\n\n Parameters\n ----------\n u : (N,) array_like, bool\n Input array.\n v : (N,) array_like, bool\n Input array.\n\n Returns\n -------\n russellrao : double\n The Russell-Rao dissimilarity between vectors u
and v
.\n\n ’
What’s the most efficient way to turn this into a format where you can format it nicely as a matplotlib text object?
I tried:
fig = plt.figure()
ax = fig.add_subplot(111)
props = dict(boxstyle=‘round’, facecolor=‘wheat’, alpha=0.5)
textstr = dist_fcn.doc
textstr = textstr.replace(‘math:’,’ ')
textstr = textstr.replace(’`’, ‘$’)
textstr = textstr.replace(’\n\n where’, ‘$\n\n where’)
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
verticalalignment=‘top’, bbox=props)
Which does an ‘ok’ job, at best, since fractions aren’t converted properly. Is there a way to do it nicely short of using some horrendous regular expressions?
Federico