Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nils Tesdal
python-leksjoner
Commits
cc1afea4
Commit
cc1afea4
authored
Feb 05, 2018
by
Nils Tesdal
Browse files
Update mini-python-course.md
parent
80c23449
Changes
1
Hide whitespace changes
Inline
Side-by-side
mini-python-course.md
View file @
cc1afea4
...
...
@@ -924,14 +924,26 @@ Hvis installasjonen er vellykket skal `matplotlib` komme opp i listen over insta

For å importere biblioteket i koden skriver vi dette øverst i kodefilen
:
Nå er vi klare til å bruke biblioteket. La oss lage et stolpediagram
:
```
python
import
matplotlib
import
matplotlib.pyplot
as
plt
import
numpy
as
np
def
show_histogram
(
counts
,
labels
,
ylabel
,
xlabel
):
x
=
np
.
arange
(
len
(
counts
))
plt
.
bar
(
x
,
height
=
counts
)
plt
.
xticks
(
x
,
labels
);
plt
.
ylabel
(
ylabel
)
plt
.
xlabel
(
xlabel
)
plt
.
show
()
# Test funksjon
show_histogram
([
2
,
16
,
3
,
1
,
4.5
],
[
"a"
,
"b"
,
"c"
,
"d"
,
"e"
],
"Antall"
,
xlabel
=
"Kategori"
)
```
Nå er vi klare til å bruke biblioteket.
Dette gjør at følgende vindu popper opp:
La oss lage et stolpediagram:

Write
Preview
Supports
Markdown
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