Jupyter-to-Tex/Example.ipynb

242 lines
5.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f536eab6-2776-4535-972a-3ece6be99b3a",
"metadata": {},
"outputs": [],
"source": [
"# Some configs that should not be shown!\n",
"import warnings\n",
"\n",
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)"
]
},
{
"cell_type": "markdown",
"id": "f6597a28-a4fc-46bb-a9b2-3cafbc944ef5",
"metadata": {},
"source": [
"# Start here\n",
"# First headline\n",
"Some nice text!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0c9dbddc-f5f5-4f58-a2e2-dfff0faf517f",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"[notice] A new release of pip available: 22.3 -> 22.3.1\n",
"[notice] To update, run: python.exe -m pip install --upgrade pip\n",
"\n",
"[notice] A new release of pip available: 22.3 -> 22.3.1\n",
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
]
}
],
"source": [
"!pip install pandas==1.5.2 -q\n",
"!pip install matplotlib==3.6.2 -q"
]
},
{
"cell_type": "markdown",
"id": "8f41454c-0bf0-4e53-992b-34fb47bf7dd1",
"metadata": {},
"source": [
"Import the classes necessary to run the software."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5c4c7d02-c06b-49c3-a6e6-9819e9eae44b",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "2e5173f8-7c64-40f4-8fbe-e3bf28ad96a3",
"metadata": {},
"source": [
"A bit of sample code!"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "66ada60d-8a49-473b-bc38-a40999ba761a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "362880"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = 1\n",
"for i in range(1, 10):\n",
" a *= i\n",
"a"
]
},
{
"cell_type": "markdown",
"id": "3dbc2840-9793-4a92-802b-78d0b333e632",
"metadata": {},
"source": [
"Acces a document by key."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "5e5fd8c8-200f-4857-b63d-1172b842f11c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "{'test': 1, 'more content': 'some_more1', 'more content1': 'some_more2'}"
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# get a document by key\n",
"some_dict = {\"test\": 1, \"more content\": \"some_more1\", \"more content1\": \"some_more2\"}\n",
"some_dict"
]
},
{
"cell_type": "markdown",
"id": "e818c095-e2d9-40c7-9234-ceddcb27cddb",
"metadata": {},
"source": [
"Pandas Example!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8eb6d0be-9fc0-4c89-ad18-801c0349d5cc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{tabular}{lrll}\n",
"\\toprule\n",
"{} & test & more content & more content1 \\\\\n",
"\\midrule\n",
"0 & 1 & some\\_more1 & some\\_more2 \\\\\n",
"1 & 1 & some\\_more1 & some\\_more2 \\\\\n",
"2 & 1 & some\\_more1 & some\\_more2 \\\\\n",
"3 & 1 & some\\_more1 & some\\_more2 \\\\\n",
"4 & 1 & some\\_more1 & some\\_more2 \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"\n"
]
}
],
"source": [
"df = pd.DataFrame([some_dict] * 10)\n",
"print(df.head().to_latex())"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "c1237c23-2ab4-4fa0-9895-0691c20827b6",
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"N = 400\n",
"t = np.linspace(0, 2 * np.pi, N)\n",
"r = 0.5 + np.cos(t)\n",
"x, y = r * np.cos(t), r * np.sin(t)\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.plot(x, y, \"k\")\n",
"ax.set(aspect=1)\n",
"plt.show()\n",
"plt.savefig(\"diagramm.png\")"
]
},
{
"cell_type": "markdown",
"source": [
"# End here\n",
"\n",
"This should not be shown!"
],
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (2007221166.py, line 3)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"C:\\Users\\phhor\\AppData\\Local\\Temp\\ipykernel_2708\\2007221166.py\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m This should not be shownm\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"execution_count": 1
},
{
"cell_type": "code",
"execution_count": 7,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}