Skip to content
Snippets Groups Projects
Commit cc1afea4 authored by Nils Tesdal's avatar Nils Tesdal
Browse files

Update mini-python-course.md

parent 80c23449
Branches
No related tags found
No related merge requests found
...@@ -924,14 +924,26 @@ Hvis installasjonen er vellykket skal `matplotlib` komme opp i listen over insta ...@@ -924,14 +924,26 @@ Hvis installasjonen er vellykket skal `matplotlib` komme opp i listen over insta
![](images/Thonny18.png) ![](images/Thonny18.png)
For å importere biblioteket i koden skriver vi dette øverst i kodefilen: Nå er vi klare til å bruke biblioteket. La oss lage et stolpediagram:
```python ```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: ![](images/Thonny18.png)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment