Skip to content

Commit

Permalink
Change from sns.set() to sns.set_theme()
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad committed Mar 3, 2024
1 parent 48c9bda commit 84d672b
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"import pandas as pd\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"import seaborn as sns\n",
"import pandas as pd\n",
"import numpy as np\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"n = 1000\n",
"cor = [-0.99, -0.7, -0.5, -0.2, 0, 0.2, 0.5, 0.7, 0.99]\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"import seaborn as sns\n",
"import numpy as np\n",
"%matplotlib inline\n",
"sns.set()\n",
"sns.set_theme()\n",
"# das was wir brauchen in abgekürzter Form"
]
},
Expand Down Expand Up @@ -1203,7 +1203,7 @@
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"sns.set()\n",
"sns.set_theme()\n",
"plt.figure(figsize=(16, 6))\n",
"my_order =['0 to 9 years', '10 to 19 years', '20 to 24 years', '25 to 34 years', '35 to 44 years', '45 to 54 years', '55 to 59 years', '60 to 64 years', '65 to 74 years', '75 years and over']\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"sns.set()\n",
"sns.set_theme()\n",
"df = pd.read_csv(\"../data/Library_Usage.csv\",\n",
" low_memory=False\n",
")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"dat = pd.DataFrame()\n",
"vals = [0.8, 1, 4]\n",
Expand Down
2 changes: 1 addition & 1 deletion content/descriptive_statistics/univariate/symmetrie.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Mit dem folgenden Beispiel kannst Du ein Histogramm über die Anzahl der Ausleih
import pandas as pd
import seaborn as sns
%matplotlib inline
sns.set()
sns.set_theme()
df = pd.read_csv("../data/Library_Usage.csv")
sns.distplot(df['Total Checkouts'], kde=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"import seaborn as sns\n",
"# command to print plots directly in jupyter\n",
"%matplotlib inline \n",
"sns.set() # sets the default seaborn theme\n",
"sns.set_theme() # sets the default seaborn theme\n",
"\n",
"df = pd.read_csv(\"../data/Library_Usage.csv\")\n",
"df.columns"
Expand Down Expand Up @@ -66,7 +66,7 @@
"import seaborn as sns\n",
"# command to print plots directly in jupyter\n",
"%matplotlib inline\n",
"sns.set() # sets the default seaborn theme\n",
"sns.set_theme() # sets the default seaborn theme\n",
"\n",
"# use sample to generate a random subsample\n",
"df = pd.read_csv(\"../../../data/Library_Usage.csv\").sample(n=1000)\n",
Expand Down
2 changes: 1 addition & 1 deletion content/descriptive_statistics/visualizations/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# matplotlib inline
sns.set()
sns.set_theme()

df = pd.read_csv("../data/Library_Usage.csv")

Expand Down
4 changes: 2 additions & 2 deletions content/descriptive_statistics/visualizations/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Die zahlreichen Funktionen, die `seaborn` bietet basieren immer auf dem gleichen

Zuerst werden die benötigten Bibliotheken importiert und der Datensatz eingelesen. Panadas und numpy dienen zur Verarbeitung der Daten. **Seaborn** baut auf **matplotlib**, der Standard-Bibliothek für wissenschaftliche Grafiken, auf und bietet einige Verbesserungen und Vereinfachungen. Der Kommentar `% matplotlib inline` ist ein [Magic Command](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-matplotlib) für den Python Kernel in Jupyter Notebooks. Mit diesem Befehl werden Plots direkt im Notebook angezeigt.

Mit `sns.set()` wird das grundlegende Design der Plots dem Design von Seaborn angepasst. Die Funktion `DataFrame.sample()` wird verwendet, um eine Zufalsstichprobe der Größe $n=1000$ aus dem Datenstatz zu erstellen. Dies dient zur **besseren Lesbarkeit** des Plots in diesem Tutorial.
Mit `sns.set_theme()` wird das grundlegende Design der Plots dem Design von Seaborn angepasst. Die Funktion `DataFrame.sample()` wird verwendet, um eine Zufalsstichprobe der Größe $n=1000$ aus dem Datenstatz zu erstellen. Dies dient zur **besseren Lesbarkeit** des Plots in diesem Tutorial.

{{% customnotice code%}}
```python
Expand All @@ -40,7 +40,7 @@ import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
%matplotlib inline
sns.set()
sns.set_theme()

# use sample to generate a random subsample
df = pd.read_csv("../data/Library_Usage.csv").sample(n=1000)
Expand Down
2 changes: 1 addition & 1 deletion content/inference/bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Die Mittelwerte jeder Simulation werden in der Liste `x_means` abgespeichert. Di
```python
#matplotlib inline
import seaborn as sns
sns.set()
sns.set_theme()
sns.distplot(x_means, kde=False, bins=35)
```

Expand Down
2 changes: 1 addition & 1 deletion content/organisation/quiz_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ LastModifierEmail = ""
{{< quiz vorbereitung_quiz>}}
{{< item question="1. Mit welcher Tastenkombination kannst Du Zellen in Jupyter Notebooks ausführen?" answer=3 choices="Strg+R,Enter,Strg+Enter" >}}
{{< item question="2. Wie viele Zeilen enthält der San Francisco Library Usage Datensatz?" answer=2 choices="423448,436290,493515,4210398" >}}
{{< item question="3. Was macht die Funktion sns.set() aus dem seaborn package?" answer=3 choices="das Paket seaborn wird importiert,dem Paket wird der kürzere Name sns zugewiesen,das Standard-Design von mit matplotlib generierten Plots wird angepasst" >}}
{{< item question="3. Was macht die Funktion sns.set_theme() aus dem seaborn package?" answer=3 choices="das Paket seaborn wird importiert,dem Paket wird der kürzere Name sns zugewiesen,das Standard-Design von mit matplotlib generierten Plots wird angepasst" >}}
{{< /quiz >}}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"\n",
"# sns.set() verschönert das Aussehen der plots\n",
"sns.set()\n",
"# sns.set_theme() verschönert das Aussehen der plots\n",
"sns.set_theme()\n",
"\n",
"# 100 normalverteilte Zahlen werden generiert\n",
"random_numbers = np.random.normal(size = 100)\n",
Expand Down
6 changes: 3 additions & 3 deletions content/organisation/recap_python/packages/seaborn.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ description = "Verbesserung und Weiterentwicklung der matplotlib Bibliothek."

[seaborn](https://seaborn.pydata.org/) baut auf matplotlib auf und bietet eine Vielzahl von Funktionen, die es erlauben schnell und einfach schöne statistische Visualisierungen zu erstellen. Seaborn ist also keine komplett eigenenständige Graphik-Bibliothek, sondern nutzt intern die Funktionalitäten und Datenstrukturen von matplotlib.

Eine wichtige Funktion ist die `sns.set()` Methode. Wenn sie am Anfang eines Python-Scripts ausgeführt wird, wird intern das Design der Plots erheblich verbessert. Alle plots, die nach dem Aufruf der Funktion erstellt werden, sehen viel besser aus.
Eine wichtige Funktion ist die `sns.set_theme()` Methode. Wenn sie am Anfang eines Python-Scripts ausgeführt wird, wird intern das Design der Plots erheblich verbessert. Alle plots, die nach dem Aufruf der Funktion erstellt werden, sehen viel besser aus.

Teste den Unterschied mit dem folgenden Beispiel:

Expand All @@ -37,7 +37,7 @@ import matplotlib.pyplot as plt
import seaborn as sns

# setup the seaborn library
sns.set()
sns.set_theme()

# create the same plot as in the previous example
x = range(1, 10)
Expand All @@ -46,5 +46,5 @@ plt.plot(x, x)
{{% /customnotice %}}

{{% customnotice tip%}}
Wenn Du im Jupyter Notebook das Code-Beispiel ausgeführst hast und danach den Aufruf `sns.set()` entfernst, ändert sich das Design des Plots erstmal nicht. Für einen "Reset" musst Du den Kernel (also der im Hintergrund laufende Python Prozess) mit einem Klick auf <i class="fas fa-redo"></i> neu starten.
Wenn Du im Jupyter Notebook das Code-Beispiel ausgeführst hast und danach den Aufruf `sns.set_theme()` entfernst, ändert sich das Design des Plots erstmal nicht. Für einen "Reset" musst Du den Kernel (also der im Hintergrund laufende Python Prozess) mit einem Klick auf <i class="fas fa-redo"></i> neu starten.
{{% /customnotice %}}
2 changes: 1 addition & 1 deletion content/organisation/solutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ LastModifierEmail = ""

1. Strg+Enter
2. 436290, `len(df)`
3. siehe (unter `sns.set()`): https://seaborn.pydata.org/introduction.html
3. siehe (unter `sns.set_theme()`): https://seaborn.pydata.org/introduction.html
4 changes: 2 additions & 2 deletions content/solutions.files/Musterloesung_Projektaufgabe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"import seaborn as sns\n",
"import numpy as np\n",
"%matplotlib inline\n",
"sns.set()\n",
"sns.set_theme()\n",
"# das was wir brauchen in abgekürzter Form"
]
},
Expand Down Expand Up @@ -1203,7 +1203,7 @@
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"sns.set()\n",
"sns.set_theme()\n",
"plt.figure(figsize=(16, 6))\n",
"my_order =['0 to 9 years', '10 to 19 years', '20 to 24 years', '25 to 34 years', '35 to 44 years', '45 to 54 years', '55 to 59 years', '60 to 64 years', '65 to 74 years', '75 years and over']\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion content/solutions.files/solutions_boxplots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"import pandas as pd\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion content/solutions.files/solutions_case_study.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"import pandas as pd\n",
"import seaborn as sns\n",
"%matplotlib inline\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"df = pd.read_csv(\"../data/Library_Usage_Clean.csv\",\n",
" low_memory=False\n",
Expand Down
2 changes: 1 addition & 1 deletion content/solutions.files/solutions_outlier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"sns.set()\n",
"sns.set_theme()\n",
"df = pd.read_csv(\"../data/Library_Usage.csv\",\n",
" low_memory=False\n",
")"
Expand Down
2 changes: 1 addition & 1 deletion content/solutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Hier finden sich die Musterlösungen aller Einheiten im Überblick.
1. Strg+Enter
2. siehe hier: https://docs.anaconda.com/anaconda/packages/pkg-docs/
3. 423448, `len(df)`
4. siehe (unter `sns.set()`): https://seaborn.pydata.org/introduction.html
4. siehe (unter `sns.set_theme()`): https://seaborn.pydata.org/introduction.html
### 2. Grundlagen der Datenanalyse in Python
Expand Down
2 changes: 1 addition & 1 deletion public/images/boxplots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"import pandas as pd\n",
"\n",
Expand Down
Binary file modified public/images/boxplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion static/images/boxplots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"sns.set()\n",
"sns.set_theme()\n",
"\n",
"import pandas as pd\n",
"\n",
Expand Down

0 comments on commit 84d672b

Please sign in to comment.