Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Distributed Computing
Common
praktikanten-material
Commits
2d6cc7cb
Commit
2d6cc7cb
authored
Oct 01, 2019
by
Raffaele Grosso
Browse files
Improve plot in Python notebook
parent
0a9abf6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/Praktikanten_Uebungen.ipynb
View file @
2d6cc7cb
...
...
@@ -491,21 +491,21 @@
```
python
import
numpy
as
np
import
matplotlib.pyplot
as
plt
# next line to embed figures in the notebook without opening a new window
%
matplotlib
inline
x
=
np
.
arange
(
0
,
4
,
0.1
)
y
sin
=
np
.
sin
(
x
)
y
cos
=
np
.
cos
(
x
)
plt
.
plot
(
y
sin
)
plt
.
plot
(
y
cos
)
x
=
np
.
arange
(
-
np
.
pi
,
np
.
pi
,
0.05
)
sin
x
=
np
.
sin
(
x
)
cos
x
=
np
.
cos
(
x
)
plt
.
plot
(
x
,
sin
x
)
plt
.
plot
(
x
,
cos
x
)
plt
.
show
()
```
%%%% Output: display_data


%% Cell type:markdown id: tags:
### b)
...
...
@@ -539,30 +539,30 @@
```
python
birth_months
=
{
"Einstein"
:
3
,
"Hawking"
:
1
,
"Newton"
:
1
,
"Franklin"
:
1
,
"Darwin"
:
2
,
"Curie"
:
11
,
"Pasteur"
:
12
,
"Copernicus"
:
1
,
"Fleming"
:
8
,
"Nobel"
:
10
,
"Mendelev"
:
2
,
"Bohr"
:
10
,
"Mendel"
:
7
,
"Faraday"
:
9
,
"Watson"
:
4
,
"Hubble"
:
11
,
"Feynman"
:
5
,
"Rutherford"
:
8
}
labels
=
[
'Jan'
,
'Feb'
,
'Mär'
,
'Apr'
,
'Mai'
,
'Jun'
,
'Jul'
,
'Aug'
,
'Sep'
,
'Oct'
,
'Nov'
,
'Dec'
]
xpos
=
np
.
arange
(
0.5
,
1
3
,
1
.0
)
# the bins argument of hist is the list of bin edges, first and last included
xpos
=
np
.
arange
(
0.5
,
1
2.6
,
1
)
# the bins argument of hist is the list of bin edges, first and last included
plt
.
hist
(
birth_months
.
values
(),
xpos
)
plt
.
xticks
(
xpos
+
0.5
,
labels
,
rotation
=
'vertical'
)
```
%%%% Output: execute_result
([<matplotlib.axis.XTick at 0x7f
4f5f2c8d3
0>,
<matplotlib.axis.XTick at 0x7f
4f5f3be550
>,
<matplotlib.axis.XTick at 0x7f
4f5f2fb1d0
>,
<matplotlib.axis.XTick at 0x7f
4f5f2814
a8>,
<matplotlib.axis.XTick at 0x7f
4f5f281b0
0>,
<matplotlib.axis.XTick at 0x7f
4f5f2
88198>,
<matplotlib.axis.XTick at 0x7f
4f5f2887
f0>,
<matplotlib.axis.XTick at 0x7f
4f5f288e8
0>,
<matplotlib.axis.XTick at 0x7f
4f5f28e5
50>,
<matplotlib.axis.XTick at 0x7f
4f5f28ebe
0>,
<matplotlib.axis.XTick at 0x7f
4f5f2932
b0>,
<matplotlib.axis.XTick at 0x7f
4f5f29394
0>,
<matplotlib.axis.XTick at 0x7f
4f5f293fd
0>],
([<matplotlib.axis.XTick at 0x7f
9b408ca40
0>,
<matplotlib.axis.XTick at 0x7f
9b409b4518
>,
<matplotlib.axis.XTick at 0x7f
9b4096aac8
>,
<matplotlib.axis.XTick at 0x7f
9b408f9b
a8>,
<matplotlib.axis.XTick at 0x7f
9b4088124
0>,
<matplotlib.axis.XTick at 0x7f
9b40
881
8
98>,
<matplotlib.axis.XTick at 0x7f
9b40881e
f0>,
<matplotlib.axis.XTick at 0x7f
9b408885c
0>,
<matplotlib.axis.XTick at 0x7f
9b40888c
50>,
<matplotlib.axis.XTick at 0x7f
9b4088d32
0>,
<matplotlib.axis.XTick at 0x7f
9b4088d9
b0>,
<matplotlib.axis.XTick at 0x7f
9b4089408
0>,
<matplotlib.axis.XTick at 0x7f
9b4089471
0>],
<a list of 12 Text xticklabel objects>)
%%%% Output: display_data

...
...
@@ -574,11 +574,11 @@
%% Cell type:code id: tags:
```
python
mu
=
100
;
sigma
=
15
#mean and sigma of the gaussian
np
.
random
.
seed
(
19340867
)
sim_data
=
mu
+
np
.
random
.
randn
(
600
)
*
sigma
# 600 random values generated from a standard normal
sim_data
=
mu
+
np
.
random
.
randn
(
600
0
)
*
sigma
# 600 random values generated from a standard normal
n_bins
=
50
fig
,
ax
=
plt
.
subplots
()
n
,
bins
,
patches
=
ax
.
hist
(
sim_data
,
n_bins
,
density
=
1
)
#as 'best fit' line use the gaussian used to generate the simulated data
y
=
1
/
(
np
.
sqrt
(
2
*
np
.
pi
)
*
sigma
)
*
np
.
exp
(
-
0.5
*
((
bins
-
mu
)
/
sigma
)
**
2
)
...
...
@@ -592,6 +592,12 @@
plt
.
show
()
```
%%%% Output: display_data


%% Cell type:code id: tags:
```
python
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment