Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Example Profile
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RWTHjupyter
Example Profile
Commits
7bf1e715
Commit
7bf1e715
authored
2 years ago
by
Christian Rohlfing
Browse files
Options
Downloads
Patches
Plain Diff
Update Quickstart.ipynb
parent
bea1fb9b
No related branches found
No related tags found
1 merge request
!10
Update Quickstart.ipynb to reflect changes in rwth_nb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Quickstart.ipynb
+5
-19
5 additions, 19 deletions
Quickstart.ipynb
with
5 additions
and
19 deletions
Quickstart.ipynb
+
5
−
19
View file @
7bf1e715
...
@@ -105,7 +105,7 @@
...
@@ -105,7 +105,7 @@
"source": [
"source": [
"%matplotlib widget\n",
"%matplotlib widget\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.pyplot as plt\n",
"
from rwth_colors_matplotlib import *
\n",
"
import rwth_nb.plots.mpl_decorations as rwth_plots
\n",
"\n",
"\n",
"fs = 44100;\n",
"fs = 44100;\n",
"(t, deltat) = np.linspace(-10, 10, 20*fs, retstep=True) # t axis in seconds\n",
"(t, deltat) = np.linspace(-10, 10, 20*fs, retstep=True) # t axis in seconds\n",
...
@@ -115,19 +115,6 @@
...
@@ -115,19 +115,6 @@
"ax.set_xlabel(r'$t$'); ax.set_ylabel(r'$s(t) = \\sin(2 \\pi t)$'); "
"ax.set_xlabel(r'$t$'); ax.set_ylabel(r'$s(t) = \\sin(2 \\pi t)$'); "
]
]
},
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from scipy import misc\n",
"f = misc.face()\n",
"\n",
"fig,ax = plt.subplots();\n",
"ax.imshow(f);"
]
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
...
@@ -204,10 +191,9 @@
...
@@ -204,10 +191,9 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"from rwth_colors_matplotlib import *\n",
"\n",
"# adapted from https://matplotlib.org/2.0.0/examples/color/named_colors.html\n",
"# adapted from https://matplotlib.org/2.0.0/examples/color/named_colors.html\n",
"colors = rwth_colors;\n",
"\n",
"colors = rwth_plots.colors.rwth_colors;\n",
"ncols = 5; nrows = len(colors.keys()) // ncols + 1;\n",
"ncols = 5; nrows = len(colors.keys()) // ncols + 1;\n",
" \n",
" \n",
"fig, ax = plt.subplots()\n",
"fig, ax = plt.subplots()\n",
...
@@ -264,7 +250,7 @@
...
@@ -264,7 +250,7 @@
],
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3
(ipykernel)
",
"language": "python",
"language": "python",
"name": "python3"
"name": "python3"
},
},
...
@@ -278,7 +264,7 @@
...
@@ -278,7 +264,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.
7.3
"
"version": "3.
9.7
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:


# Jupyter Example Profile Quickstart
# Jupyter Example Profile Quickstart
Welcome to JupyterLab!
Welcome to JupyterLab!
*
Execute a single cell:
<span
class=
"fa-play fa"
></span>
*
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
*
Execute all cells: Menu: Run
<span
class=
"fa-chevron-right fa"
></span>
Run All Cells
*
To reboot kernel:
<span
class=
"fa-refresh fa"
></span>
*
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).
Find more in the reference (menu: Help
<span
class=
"fa-chevron-right fa"
></span>
Jupyter Reference).
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Markdown
## Markdown
You can specify the cell type which is either _Code_ or _Markdown_.
You can specify the cell type which is either _Code_ or _Markdown_.
### Lists
### Lists
*
Like
*
Like
*
this
*
this
1.
We can even nest them like
1.
We can even nest them like
2.
this!
2.
this!
*
Isn't that wonderfull?
*
Isn't that wonderfull?
### Images
### Images


### LaTeX equations
### LaTeX equations
$$
\m
athrm{e}^{
\m
athrm{j} x} =
\c
os(x)+
\m
athrm{j}
\s
in(x)$$
$$
\m
athrm{e}^{
\m
athrm{j} x} =
\c
os(x)+
\m
athrm{j}
\s
in(x)$$
### Code
### Code
```
python
```
python
print
(
"
Hello world!
"
)
print
(
"
Hello world!
"
)
```
```
### Further reading
### Further reading
Read more in the reference (menu: Help
<span
class=
"fa-chevron-right fa"
></span>
Markdown Reference).
Read more in the reference (menu: Help
<span
class=
"fa-chevron-right fa"
></span>
Markdown Reference).
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Python
## Python
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
print
(
"
Hello world!
"
)
print
(
"
Hello world!
"
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## numpy
## numpy
Execute the cell below to see the contents of variable
`a`
Execute the cell below to see the contents of variable
`a`
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
numpy
as
np
import
numpy
as
np
a
=
np
.
array
([
0
,
1
,
-
5
])
a
=
np
.
array
([
0
,
1
,
-
5
])
a
a
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Plots with matplotlib
## Plots with matplotlib
Nice matplotlib
[
tutorial
](
https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py
)
Nice matplotlib
[
tutorial
](
https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py
)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
%
matplotlib
widget
%
matplotlib
widget
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
rwth_colors_matplotlib
import
*
import
rwth_nb.plots.mpl_decorations
as
rwth_plots
fs
=
44100
;
fs
=
44100
;
(
t
,
deltat
)
=
np
.
linspace
(
-
10
,
10
,
20
*
fs
,
retstep
=
True
)
# t axis in seconds
(
t
,
deltat
)
=
np
.
linspace
(
-
10
,
10
,
20
*
fs
,
retstep
=
True
)
# t axis in seconds
fig
,
ax
=
plt
.
subplots
();
ax
.
grid
();
fig
,
ax
=
plt
.
subplots
();
ax
.
grid
();
ax
.
plot
(
t
,
np
.
sin
(
2
*
np
.
pi
*
t
),
'
rwth:blue
'
)
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)$
'
);
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:
%% Cell type:markdown id: tags:
## Interactive Widgets
## Interactive Widgets
Jupyter Widgets. You can find a detailled widget list
[
here
](
https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html
)
.
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.
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
)
.
Uses Python
[
decorators
](
https://docs.python.org/3/glossary.html#term-decorator
)
.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
ipywidgets
as
widgets
import
ipywidgets
as
widgets
# Create figure
# Create figure
fig0
,
ax0
=
plt
.
subplots
();
fig0
,
ax0
=
plt
.
subplots
();
# Create update function and decorate them with widgets
# 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$:
'
))
@widgets.interact
(
F
=
widgets
.
FloatSlider
(
min
=
0.1
,
max
=
10
,
step
=
0.1
,
value
=
0
,
description
=
'
$F$:
'
))
def
update_plot
(
F
):
def
update_plot
(
F
):
# Generate signal with given F
# Generate signal with given F
s
=
np
.
sin
(
2
*
np
.
pi
*
F
*
t
)
s
=
np
.
sin
(
2
*
np
.
pi
*
F
*
t
)
# Plot
# Plot
if
not
ax0
.
lines
:
# decorate axes with labels etc. (which is only needed once)
if
not
ax0
.
lines
:
# decorate axes with labels etc. (which is only needed once)
ax0
.
plot
(
t
,
s
,
'
rwth:blue
'
);
ax0
.
plot
(
t
,
s
,
'
rwth:blue
'
);
ax0
.
set_xlabel
(
r
'
$t$
'
);
ax
.
set_ylabel
(
r
'
$s(t)=\sin(2 \pi F t)$
'
)
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)
else
:
# update only lines and leave everything else as is (gives huge speed-up)
ax0
.
lines
[
0
].
set_ydata
(
s
)
ax0
.
lines
[
0
].
set_ydata
(
s
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Audio
## Audio
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
from
IPython.display
import
Audio
,
Latex
from
IPython.display
import
Audio
,
Latex
def
audio_play
(
s
,
fs
,
txt
=
""
,
autoplay
=
False
):
def
audio_play
(
s
,
fs
,
txt
=
""
,
autoplay
=
False
):
if
txt
:
display
(
Latex
(
txt
))
if
txt
:
display
(
Latex
(
txt
))
display
(
Audio
(
s
,
rate
=
fs
,
autoplay
=
autoplay
))
display
(
Audio
(
s
,
rate
=
fs
,
autoplay
=
autoplay
))
# Create sin
# Create sin
s
=
np
.
sin
(
2
*
np
.
pi
*
440
*
t
)
s
=
np
.
sin
(
2
*
np
.
pi
*
440
*
t
)
# Play back
# Play back
audio_play
(
s
,
fs
,
r
'
$s(t)$
'
)
audio_play
(
s
,
fs
,
r
'
$s(t)$
'
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## RWTH Colors
## RWTH Colors
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
from
rwth_colors_matplotlib
import
*
# adapted from https://matplotlib.org/2.0.0/examples/color/named_colors.html
# 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
;
ncols
=
5
;
nrows
=
len
(
colors
.
keys
())
//
ncols
+
1
;
fig
,
ax
=
plt
.
subplots
()
fig
,
ax
=
plt
.
subplots
()
X
,
Y
=
fig
.
get_dpi
()
*
fig
.
get_size_inches
()
# Get height and width
X
,
Y
=
fig
.
get_dpi
()
*
fig
.
get_size_inches
()
# Get height and width
w
=
X
/
ncols
;
h
=
Y
/
(
nrows
+
1
)
w
=
X
/
ncols
;
h
=
Y
/
(
nrows
+
1
)
for
i
,
name
in
enumerate
(
colors
.
keys
()):
for
i
,
name
in
enumerate
(
colors
.
keys
()):
col
=
i
%
ncols
col
=
i
%
ncols
row
=
i
//
ncols
row
=
i
//
ncols
y
=
Y
-
(
row
*
h
)
-
h
y
=
Y
-
(
row
*
h
)
-
h
xi_line
=
w
*
(
col
+
0.05
);
xf_line
=
w
*
(
col
+
0.25
);
xi_text
=
w
*
(
col
+
0.3
)
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
.
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
.
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
();
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
)
fig
.
subplots_adjust
(
left
=
0
,
right
=
1
,
top
=
1
,
bottom
=
0
,
hspace
=
0
,
wspace
=
0
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Magic
## Magic
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
%%
svg
%%
svg
<
svg
width
=
'
300px
'
height
=
'
300px
'
>
<
svg
width
=
'
300px
'
height
=
'
300px
'
>
<
title
>
Small
SVG
example
</
title
>
<
title
>
Small
SVG
example
</
title
>
<
circle
cx
=
'
120
'
cy
=
'
150
'
r
=
'
60
'
style
=
'
fill: gold;
'
>
<
circle
cx
=
'
120
'
cy
=
'
150
'
r
=
'
60
'
style
=
'
fill: gold;
'
>
<
animate
attributeName
=
'
r
'
from
=
'
2
'
to
=
'
80
'
begin
=
'
0
'
<
animate
attributeName
=
'
r
'
from
=
'
2
'
to
=
'
80
'
begin
=
'
0
'
dur
=
'
3
'
repeatCount
=
'
indefinite
'
/></
circle
>
dur
=
'
3
'
repeatCount
=
'
indefinite
'
/></
circle
>
<
polyline
points
=
'
120 30, 25 150, 290 150
'
<
polyline
points
=
'
120 30, 25 150, 290 150
'
stroke
-
width
=
'
4
'
stroke
=
'
brown
'
style
=
'
fill: none;
'
/>
stroke
-
width
=
'
4
'
stroke
=
'
brown
'
style
=
'
fill: none;
'
/>
<
polygon
points
=
'
210 100, 210 200, 270 150
'
<
polygon
points
=
'
210 100, 210 200, 270 150
'
style
=
'
fill: lawngreen;
'
/>
style
=
'
fill: lawngreen;
'
/>
<
text
x
=
'
60
'
y
=
'
250
'
fill
=
'
blue
'
>
Hello
,
World
!
</
text
>
<
text
x
=
'
60
'
y
=
'
250
'
fill
=
'
blue
'
>
Hello
,
World
!
</
text
>
</
svg
>
</
svg
>
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment