Demo notebook - site-with-notebooks-and-python-files
Description: mkdocs-jupyter test site

Skip to content

# Demo notebook¶

## Header 2¶

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur purus mi, sollicitudin ac justo a, dapibus ultrices dolor. Curabitur id eros mattis, tincidunt ligula at, condimentum urna.

### Header 3¶

A regular markdown code block

    id_ = 0
    for directory in directories:
        rootdir = os.path.join('/Users/drodriguez/Downloads/aclImdb', directory)
        for subdir, dirs, files in os.walk(rootdir):
            for file_ in files:
                with open(os.path.join(subdir, file_), 'r') as f:
                    doc_id = '_*%i' % id_
                    id_ = id_ + 1

                    text = f.read()
                    text = text.decode('utf-8')
                    tokens = nltk.word_tokenize(text)
                    doc = ' '.join(tokens).lower()
                    doc = doc.encode('ascii', 'ignore')
                    input_file.write('%s %s\n' % (doc_id, doc))

### More markdown things¶

> Pellentesque pretium euismod laoreet. Nullam eget mauris ut tellus vehicula consequat. In sed molestie metus. Nulla at varius nunc, sit amet semper arcu. Integer tristique augue eget auctor aliquam. Donec ornare consectetur lectus et viverra. Duis vel elit ac lectus accumsan gravida non ac erat.

Ut in ipsum id neque pellentesque iaculis. Pellentesque massa erat, rhoncus id auctor vel, tempor id neque. Nunc nec iaculis enim. Duis eget tincidunt tellus. Proin vitae ultrices velit.

1. Item 1
2. Curabitur vel enim at mi dictum venenatis eget eu nulla. Suspendisse potenti. Etiam vitae nibh a odio dictum aliquam. Sed sit amet adipiscing leo, vitae euismod arcu.
3. Item 3

Sed vestibulum justo et turpis ullamcorper, a interdum sapien tristique. Donec ullamcorper ipsum ac scelerisque lacinia. Quisque et eleifend odio. Curabitur vel enim at mi dictum venenatis eget eu nulla. Suspendisse potenti. Etiam vitae nibh a odio dictum aliquam. Sed sit amet adipiscing leo, vitae euismod arcu.

- Item 1
- Curabitur vel enim at mi dictum venenatis eget eu nulla. Suspendisse potenti. Etiam vitae nibh a odio dictum aliquam. Sed sit amet adipiscing leo, vitae euismod arcu.
- Item 3

Sed vestibulum justo et turpis ullamcorper, a interdum sapien tristique. Donec ullamcorper ipsum ac scelerisque lacinia. Quisque et eleifend odio. Curabitur vel enim at mi dictum venenatis eget eu nulla. Suspendisse potenti. Etiam vitae nibh a odio dictum aliquam. Sed sit amet adipiscing leo, vitae euismod arcu.

## Code cells¶

This first code cells have some tags

In [1]:
tag1
Copied!

    a = 1

a = 1
In [2]:
tag1
tag2
Copied!

    a

a
Out[2]:

    1

In [3]:
tag1
tag2
tag3
Copied!

    b = "pew"

b = "pew"
In [4]:
Copied!

    b

b
Out[4]:

    'pew'

In [5]:
Copied!

    import re

import re
In [6]:
Copied!

    text = "foo bar\t baz \tqux"

text = "foo bar\t baz \tqux"
In [7]:
Copied!

    re.split("\s+", text)

re.split("\s+", text)
Out[7]:

    ['foo', 'bar', 'baz', 'qux']

In [8]:
Copied!

    %%latex
    \begin{align}
    \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
    \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
    \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
    \nabla \cdot \vec{\mathbf{B}} & = 0
    \end{align}

%%latex \begin{align} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{align}
\begin{align} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{align}
In [9]:
Copied!

    import numpy as np
    import pandas as pd

import numpy as np import pandas as pd

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[9], line 1
    ----> 1 import numpy as np
          2 import pandas as pd

    ModuleNotFoundError: No module named 'numpy'

In [10]:
Copied!

    dates = pd.date_range("20130101", periods=6)
    df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))
    df

dates = pd.date_range("20130101", periods=6) df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD")) df

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[10], line 1
    ----> 1 dates = pd.date_range("20130101", periods=6)
          2 df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))
          3 df

    NameError: name 'pd' is not defined

In [11]:
Copied!

    %matplotlib inline

%matplotlib inline

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[11], line 1
    ----> 1 get_ipython().run_line_magic('matplotlib', 'inline')

    File ~/code/mkdocs-jupyter/.venv/mkdocs-jupyter/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2369, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
       2367     kwargs['local_ns'] = self.get_local_scope(stack_depth)
       2368 with self.builtin_trap:
    -> 2369     result = fn(*args, **kwargs)
       2371 # The code below prevents the output from being displayed
       2372 # when using magics with decodator @output_can_be_silenced
       2373 # when the last Python token in the expression is a ';'.
       2374 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

    File ~/code/mkdocs-jupyter/.venv/mkdocs-jupyter/lib/python3.10/site-packages/IPython/core/magics/pylab.py:99, in PylabMagics.matplotlib(self, line)
         97     print("Available matplotlib backends: %s" % backends_list)
         98 else:
    ---> 99     gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
        100     self._show_matplotlib_backend(args.gui, backend)

    File ~/code/mkdocs-jupyter/.venv/mkdocs-jupyter/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3540, in InteractiveShell.enable_matplotlib(self, gui)
       3519 def enable_matplotlib(self, gui=None):
       3520     """Enable interactive matplotlib and inline figure support.
       3521
       3522     This takes the following steps:
       (...)
       3538         display figures inline.
       3539     """
    -> 3540     from matplotlib_inline.backend_inline import configure_inline_support
       3542     from IPython.core import pylabtools as pt
       3543     gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)

    File ~/code/mkdocs-jupyter/.venv/mkdocs-jupyter/lib/python3.10/site-packages/matplotlib_inline/__init__.py:1
    ----> 1 from . import backend_inline, config  # noqa
          2 __version__ = "0.1.6"  # noqa

    File ~/code/mkdocs-jupyter/.venv/mkdocs-jupyter/lib/python3.10/site-packages/matplotlib_inline/backend_inline.py:6
          1 """A matplotlib backend for publishing figures via display_data"""
          3 # Copyright (c) IPython Development Team.
          4 # Distributed under the terms of the BSD 3-Clause License.
    ----> 6 import matplotlib
          7 from matplotlib import colors
          8 from matplotlib.backends import backend_agg

    ModuleNotFoundError: No module named 'matplotlib'

In [12]:
Copied!

    import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[12], line 1
    ----> 1 import matplotlib.pyplot as plt

    ModuleNotFoundError: No module named 'matplotlib'

In [13]:
Copied!

    from pylab import *

from pylab import *

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[13], line 1
    ----> 1 from pylab import *

    ModuleNotFoundError: No module named 'pylab'

In [14]:
Copied!

    x = linspace(0, 5, 10)
    y = x**2

x = linspace(0, 5, 10) y = x**2

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[14], line 1
    ----> 1 x = linspace(0, 5, 10)
          2 y = x**2

    NameError: name 'linspace' is not defined

In [15]:
Copied!

    figure()
    plot(x, y, "r")
    xlabel("x")
    ylabel("y")
    title("title")
    show()

figure() plot(x, y, "r") xlabel("x") ylabel("y") title("title") show()

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[15], line 1
    ----> 1 figure()
          2 plot(x, y, "r")
          3 xlabel("x")

    NameError: name 'figure' is not defined

In [16]:
Copied!

    num_points = 130
    y = np.random.random(num_points)
    plt.plot(y)

num_points = 130 y = np.random.random(num_points) plt.plot(y)

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[16], line 2
          1 num_points = 130
    ----> 2 y = np.random.random(num_points)
          3 plt.plot(y)

    NameError: name 'np' is not defined

This is some text, here comes some latex

## Javascript plots¶

### plotly¶

In [17]:
Copied!

    import plotly.express as px

import plotly.express as px

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[17], line 1
    ----> 1 import plotly.express as px

    ModuleNotFoundError: No module named 'plotly'

In [18]:
Copied!

    df = px.data.iris()
    fig = px.scatter(df, x="sepal_width", y="sepal_length")
    fig.show()

df = px.data.iris() fig = px.scatter(df, x="sepal_width", y="sepal_length") fig.show()

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[18], line 1
    ----> 1 df = px.data.iris()
          2 fig = px.scatter(df, x="sepal_width", y="sepal_length")
          3 fig.show()

    NameError: name 'px' is not defined

### bokeh¶

In [19]:
Copied!

    from bokeh.plotting import figure, output_notebook, show

from bokeh.plotting import figure, output_notebook, show

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    Cell In[19], line 1
    ----> 1 from bokeh.plotting import figure, output_notebook, show

    ModuleNotFoundError: No module named 'bokeh'

In [20]:
Copied!

    output_notebook()

output_notebook()

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[20], line 1
    ----> 1 output_notebook()

    NameError: name 'output_notebook' is not defined

In [21]:
Copied!

    p = figure()
    p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
    show(p)

p = figure() p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2) show(p)

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[21], line 1
    ----> 1 p = figure()
          2 p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
          3 show(p)

    NameError: name 'figure' is not defined

In [ ]:
Copied!