Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
"cells": [
{
"cell_type": "markdown",
"id": "ef929eed",
"metadata": {},
"source": [
"# Getting started with Jupytext\n",
"\n",
"This small notebook shows you how to activate Jupytext in the JupyterLab\n",
"environment. We'll show you a few things that you can do with Jupytext and\n",
"a bit of what happens under the hood.\n",
"\n",
"**Note: to run this notebook locally, you need to first follow the Jupytext\n",
"installation instructions and activate the JupyterLab plugin. If you're on\n",
"Binder, it should already work.**\n",
"\n",
"## Enabling Jupytext in a new notebook\n",
"\n",
"This notebook is brand new - it hasn't had any special extra metadata added\n",
"to it.\n",
"\n",
"If we want Jupytext to save files in multiple formats automatically,\n",
"we can use the JupyterLab **command palette** to do so.\n",
"\n",
"* In the _View_ menu, click on _Activate Command Palette_\n",
"* Then type **`Jupytext`**. You should see a number of commands come up. Each\n",
" one tells Jupytext to save the notebook in a different\n",
" file format automatically.\n",
"* Select **Pair notebook with Markdown**\n",
"\n",
"That's it! If you have Jupytext installed, it will now save your notebook in\n",
"markdown format automatically when you save this `.ipynb` file\n",
"**in addition to** saving the `.ipynb` file itself.\n",
"\n",
"After you've done this, save the notebook. You should now see a new file called\n",
"**`get_started.md`** in the same directory as this notebook.\n",
"\n",
"## How does Jupytext know to do this?\n",
"\n",
"Jupytext uses notebook-level metadata to keep track of what formats are paired\n",
"with a notebook. Below we'll print the metadata of this notebook so you can see\n",
"what the Jupytext metadata looks like."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "350a250f",
"metadata": {},
"outputs": [],
"source": [
"import nbformat as nbf\n",
"from IPython.display import JSON\n",
"notebook = nbf.read('./get_started.ipynb', nbf.NO_CONVERT)\n",
"JSON(notebook['metadata'])"
]
},
{
"cell_type": "markdown",
"id": "b9615e72",
"metadata": {},
"source": [
"As you select different formats from the command palette (following the instructions\n",
"above) and save the notebook, you'll see this metadata change."
]
},
{
"cell_type": "markdown",
"id": "cff7b741",
"metadata": {},
"source": [
"## That's it!\n",
"\n",
"Play around with different kinds of code and outputs to see how each is\n",
"converted into its corresponding text format. Here's a little Python code\n",
"to get you started:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1868ebe8",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.scatter(*np.random.randn(2, 100), c=np.random.randn(100), s=np.random.rand(100)*100)"
]
},
{
"cell_type": "markdown",
"id": "edb7fd45",
"metadata": {},
"source": [
"# Experiment with the demo notebook!\n",
"\n",
"In the \"demo\" folder for `jupytext` there is a notebook called **`World population.ipynb`**.\n",
"By default, saving the demo notebook will also create *many* possible Jupytext\n",
"outputs so you can see what each looks like and which you prefer."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}