0

I've just discovered that function?, like len? will bring up documentation for that function in ipython.

One library has .. math:: blocks and .. plot:: in its docs.

The former seems to need to be passed to a latex engine and the latter to a python interpreter to plot a graph which is embedded in the docs. Sadly, in my jupyter notebooks client, I just get the code for these.

Is there any way to have this code be executed by both latex and python so that I may get the intended output?

NB: A sample output pm.Exponential?


The pdf of this distribution is

.. math::

   f(x \mid \lambda) = \lambda \exp\left\{ -\lambda x \right\}

.. plot::

    import matplotlib.pyplot as plt
    import numpy as np
    import scipy.stats as st
    plt.style.use('seaborn-darkgrid')
    x = np.linspace(0, 3, 100)
    for lam in [0.5, 1., 2.]:
        pdf = st.expon.pdf(x, scale=1.0/lam)
        plt.plot(x, pdf, label=r'$\lambda$ = {}'.format(lam))
    plt.xlabel('x', fontsize=12)
    plt.ylabel('f(x)', fontsize=12)
    plt.legend(loc=1)
    plt.show()

========  ============================
Support   :math:`x \in [0, \infty)`
Mean      :math:`\dfrac{1}{\lambda}`
Variance  :math:`\dfrac{1}{\lambda^2}`
========  ============================

Parameters
----------
lam: float
    Rate or inverse scale (lam > 0)
File:           ~/.local/lib/python3.9/site-packages/pymc3/distributions/continuous.py
Type:           type
Subclasses:    
5
  • 1
    These directives are used by sphinx to compile docs from the source code. They are not expected to be properly rendered in function signature. Commented Nov 11, 2021 at 21:50
  • If you're looking to document your code in a notebook, Google Colabs have great support for this- even including LaTeX. Commented Nov 11, 2021 at 21:51
  • Does this answer your question? How to display a graph in ipython notebook Commented Nov 11, 2021 at 21:55
  • @Marat do you have a quick cli command I can use to take that source from stdin and compile it to a pdf? I'm looking to make myself a helper in my bashrc that will compile the sphinx source Commented Nov 11, 2021 at 22:04
  • 1
    @Edward I'd expect this to be a non-trivial task. Compiling sphinx docs often relies on having specific versions of dependencies and non-trivial hacks. It's probably easier to write a helper to find links to already compiled documentation rather than compile it yourself Commented Nov 11, 2021 at 22:17

1 Answer 1

0

nbdev + fastbook gives me what I want.

The following snippet gives the intended result.

!pip install torch nbdev fastbook
import fastbook
fastbook.setup_book()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.