Skip to content
Snippets Groups Projects
Commit 7bf1e715 authored by Christian Rohlfing's avatar Christian Rohlfing
Browse files

Update Quickstart.ipynb

parent bea1fb9b
No related branches found
No related tags found
1 merge request!10Update Quickstart.ipynb to reflect changes in rwth_nb
%% Cell type:markdown id: tags:
![RWTH Logo](https://www.rwth-aachen.de/global/show_picture.asp?id=aaaaaaaaaaagazb)
# Jupyter Example Profile Quickstart
Welcome to JupyterLab!
* Execute a single cell: <span class="fa-play fa"></span>
* Execute all cells: Menu: Run <span class="fa-chevron-right fa"></span> Run All Cells
* To reboot kernel: <span class="fa-refresh fa"></span>
Find more in the reference (menu: Help <span class="fa-chevron-right fa"></span> Jupyter Reference).
%% Cell type:markdown id: tags:
## Markdown
You can specify the cell type which is either _Code_ or _Markdown_.
### Lists
* Like
* this
1. We can even nest them like
2. this!
* Isn't that wonderfull?
### Images
![Newtons cradle](https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Newtons_cradle_animation_book_2.gif/200px-Newtons_cradle_animation_book_2.gif)
### LaTeX equations
$$\mathrm{e}^{\mathrm{j} x} = \cos(x)+\mathrm{j}\sin(x)$$
### Code
``` python
print("Hello world!")
```
### Further reading
Read more in the reference (menu: Help <span class="fa-chevron-right fa"></span> Markdown Reference).
%% Cell type:markdown id: tags:
## Python
%% Cell type:code id: tags:
``` python
print("Hello world!")
```
%% Cell type:markdown id: tags:
## numpy
Execute the cell below to see the contents of variable `a`
%% Cell type:code id: tags:
``` python
import numpy as np
a = np.array([0, 1, -5])
a
```
%% Cell type:markdown id: tags:
## Plots with matplotlib
Nice matplotlib [tutorial](https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py)
%% Cell type:code id: tags:
``` python
%matplotlib widget
import matplotlib.pyplot as plt
from rwth_colors_matplotlib import *
import rwth_nb.plots.mpl_decorations as rwth_plots
fs = 44100;
(t, deltat) = np.linspace(-10, 10, 20*fs, retstep=True) # t axis in seconds
fig,ax = plt.subplots(); ax.grid();
ax.plot(t, np.sin(2*np.pi*t), 'rwth:blue')
ax.set_xlabel(r'$t$'); ax.set_ylabel(r'$s(t) = \sin(2 \pi t)$');
```
%% Cell type:code id: tags:
``` python
from scipy import misc
f = misc.face()
fig,ax = plt.subplots();
ax.imshow(f);
```
%% Cell type:markdown id: tags:
## Interactive Widgets
Jupyter Widgets. You can find a detailled widget list [here](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html).
This requires to install [Jupyter Matplotlib](https://github.com/matplotlib/jupyter-matplotlib) which is called with the `%matplotlib widget` magic.
Uses Python [decorators](https://docs.python.org/3/glossary.html#term-decorator).
%% Cell type:code id: tags:
``` python
import ipywidgets as widgets
# Create figure
fig0, ax0 = plt.subplots();
# Create update function and decorate them with widgets
@widgets.interact(F = widgets.FloatSlider(min=0.1, max=10, step=0.1, value=0, description='$F$:'))
def update_plot(F):
# Generate signal with given F
s = np.sin(2*np.pi*F*t)
# Plot
if not ax0.lines: # decorate axes with labels etc. (which is only needed once)
ax0.plot(t, s, 'rwth:blue');
ax0.set_xlabel(r'$t$'); ax.set_ylabel(r'$s(t)=\sin(2 \pi F t)$')
else: # update only lines and leave everything else as is (gives huge speed-up)
ax0.lines[0].set_ydata(s)
```
%% Cell type:markdown id: tags:
## Audio
%% Cell type:code id: tags:
``` python
from IPython.display import Audio, Latex
def audio_play(s, fs, txt="", autoplay=False):
if txt: display(Latex(txt))
display(Audio(s, rate=fs, autoplay=autoplay))
# Create sin
s = np.sin(2*np.pi*440*t)
# Play back
audio_play(s, fs, r'$s(t)$')
```
%% Cell type:markdown id: tags:
## RWTH Colors
%% Cell type:code id: tags:
``` python
from rwth_colors_matplotlib import *
# adapted from https://matplotlib.org/2.0.0/examples/color/named_colors.html
colors = rwth_colors;
colors = rwth_plots.colors.rwth_colors;
ncols = 5; nrows = len(colors.keys()) // ncols + 1;
fig, ax = plt.subplots()
X, Y = fig.get_dpi() * fig.get_size_inches() # Get height and width
w = X / ncols; h = Y / (nrows + 1)
for i, name in enumerate(colors.keys()):
col = i % ncols
row = i // ncols
y = Y - (row * h) - h
xi_line = w * (col + 0.05); xf_line = w * (col + 0.25); xi_text = w * (col + 0.3)
ax.text(xi_text, y, name, fontsize=10, horizontalalignment='left', verticalalignment='center')
ax.hlines(y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))
ax.set_xlim(0, X); ax.set_ylim(0, Y); ax.set_axis_off();
fig.subplots_adjust(left=0, right=1, top=1, bottom=0, hspace=0, wspace=0)
```
%% Cell type:markdown id: tags:
## Magic
%% Cell type:code id: tags:
``` python
%%svg
<svg width='300px' height='300px'>
<title>Small SVG example</title>
<circle cx='120' cy='150' r='60' style='fill: gold;'>
<animate attributeName='r' from='2' to='80' begin='0'
dur='3' repeatCount='indefinite' /></circle>
<polyline points='120 30, 25 150, 290 150'
stroke-width='4' stroke='brown' style='fill: none;' />
<polygon points='210 100, 210 200, 270 150'
style='fill: lawngreen;' />
<text x='60' y='250' fill='blue'>Hello, World!</text>
</svg>
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment