From fb58c51aa2e8d96742f7ea64e6d7b8a5e500cebe Mon Sep 17 00:00:00 2001 From: Meik Hellmund Date: Fri, 31 May 2024 20:30:57 +0200 Subject: [PATCH] plots erweitert --- .vscode/settings.json | 4 +-- _quarto.yml | 2 +- chapters/10_Strings.qmd | 33 ++++++++++++--------- chapters/13_IO.qmd | 12 ++++++-- chapters/14_Plot.qmd | 65 +++++++++++++++++++++++++++++++++++++++-- 5 files changed, 94 insertions(+), 22 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9b1508c..68e5d9b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,8 +7,8 @@ "**/CVS": true, "**/.DS_Store": true, "**/Thumbs.db": true, - "**/*.ipynb": false, - "**/*.md": false + "**/*.ipynb": true, + "**/*.md": true }, "explorerExclude.backup": {}, "ltex.enabled": false, diff --git a/_quarto.yml b/_quarto.yml index cddaf1d..e563e6b 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -54,8 +54,8 @@ book: - chapters/7_ArraysP2.qmd - chapters/11_LinAlg.qmd - chapters/10_Strings.qmd + - chapters/13_IO.qmd - chapters/14_Plot.qmd - # - chapters/13_IO.qmd # - chapters/makie.qmd diff --git a/chapters/10_Strings.qmd b/chapters/10_Strings.qmd index 0c06fc1..aeaefa7 100644 --- a/chapters/10_Strings.qmd +++ b/chapters/10_Strings.qmd @@ -52,7 +52,7 @@ Der _American Standard Code for Information Interchange_ wurde 1963 in den USA a |ISO 8859-6 (Latin/Arabic) | | |ISO 8859-7 (Latin/Greek) | | |...| | - |ISO 8859-15 (Latin-9)| | 1999: Revision von Latin-1: jetzt mit Euro-Zeichen! + |ISO 8859-15 (Latin-9)| | 1999: Revision von Latin-1: jetzt u.a. mit Euro-Zeichen ::: @@ -61,7 +61,7 @@ Der _American Standard Code for Information Interchange_ wurde 1963 in den USA a Das Ziel des Unicode-Consortiums ist eine einheitliche Codierung für alle Schriften der Welt. - Unicode Version 1 erschien 1991 -- Unicode Version 15 erschien 2021 mit 149 186 Zeichen (das sind 4489 mehr als Unicode 14), darunter: +- Unicode Version 15.1 erschien 2023 mit 149 813 Zeichen, darunter: - 161 Schriften - mathematische und technische Symbole - Emojis und andere Symbole, Steuer- und Formatierungszeichen @@ -73,7 +73,7 @@ Das Ziel des Unicode-Consortiums ist eine einheitliche Codierung für alle Schri - Jedem Zeichen wird ein `codepoint` zugeordnet. Das ist einfach eine fortlaufende Nummer. - Diese Nummer wird hexadezimal notiert - entweder 4-stellig als `U+XXXX` (0-te Ebene) - - oder 5...6-stellig als `U+XXXXXX` (weitere Ebenen) + - oder 6-stellig als `U+XXXXXX` (weitere Ebenen) - Jede Ebene geht von `U+XY0000` bis `U+XYFFFF`, kann also $2^{16}=65\;534$ Zeichen enthalten. - Vorgesehen sind bisher 17 Ebenen `XY=00` bis `XY=10`, also der Wertebereich von `U+0000` bis `U+10FFFF`. - Damit sind maximal 21 Bits pro Zeichen nötig. @@ -83,7 +83,8 @@ Das Ziel des Unicode-Consortiums ist eine einheitliche Codierung für alle Schri - Ebene 1 = SMP _Supplementary Multilingual Plane_ `U+010000 - U+01FFFF`, - Ebene 2 = SIP _Supplementary Ideographic Plane_ `U+020000 - U+02FFFF`, - Ebene 3 = TIP _Tertiary Ideographic Plane_ `U+030000 - U+03FFFF` und - - Ebene 14 = SSP _Supplementary Special-purpose Plane_ `U+0E0000 - U+0EFFFF` vergeben. + - Ebene 14 = SSP _Supplementary Special-purpose Plane_ `U+0E0000 - U+0EFFFF` + vergeben. - `U+0000` bis `U+007F` ist identisch mit ASCII - `U+0000` bis `U+00FF` ist identisch mit ISO 8859-1 (Latin-1) @@ -117,6 +118,8 @@ U+21B4 RIGHTWARDS ARROW WITH CORNER DOWNWARDS Wie sieht 'RIGHTWARDS ARROW WITH CORNER DOWNWARDS' aus? +Julia verwendet `\U...` zur Eingabe von Unicode Codepoints. + ```{julia} '\U21b4' ``` @@ -256,7 +259,7 @@ Da die Codepoints unterschiedlich lang sind, kann man sie nicht einfach hinterei - Damit ist jeder ASCII-Text automatisch auch ein korrekt codierter UTF-8-Text. -- Sollten die bisher für Unicode festgelegten 17 Ebenen = 21 Bit = 1.1 Mill. mögliche Zeichen mal erweitert werden, dann wird UTF-8 auf 5- und 6-Byte-Codes erweitert. +- Sollten die bisher für Unicode festgelegten 17 Ebenen (= 21 Bit = 1.1 Mill. mögliche Zeichen) mal erweitert werden, dann wird UTF-8 auf 5- und 6-Byte-Codes erweitert. ## Zeichen und Zeichenketten in Julia @@ -272,6 +275,17 @@ Der Datentyp `Char` kodiert ein einzelnes Unicode-Zeichen. - der Integer-Wert ist gleich dem Unicode-codepoint. +`Char`s können von/zu `UInt`s umgewandelt werden. + +```{julia} +UInt('a') +``` + + +```{julia} +b = Char(0x2656) +``` + ### Zeichenketten: `String` - Für Strings verwendet Julia doppelte Anführungszeichen: `"a"`. @@ -283,16 +297,7 @@ Der Datentyp `Char` kodiert ein einzelnes Unicode-Zeichen. ``` -- `Char`s können von/zu `UInt`s umgewandelt werden. -```{julia} -UInt('a') -``` - - -```{julia} -b = Char(0x2656) -``` __Bei einem Nicht-ASCII-String unterscheiden sich Anzahl der Bytes und Anzahl der Zeichen:__ diff --git a/chapters/13_IO.qmd b/chapters/13_IO.qmd index 2bc8e50..3db5bbb 100644 --- a/chapters/13_IO.qmd +++ b/chapters/13_IO.qmd @@ -9,7 +9,9 @@ engine: julia using InteractiveUtils ``` -# Ein- und Ausgabe I/O +# Ein- und Ausgabe + + zahlreiche Varianten und Funktionen, das Folgende ist eine kleine Auswahl @@ -37,7 +39,6 @@ zahlreiche Varianten und Funktionen, das Folgende ist eine kleine Auswahl ```{julia} -# aus dem ersten Beispielprogramm function input(prompt = "Eingabe:") println(prompt) @@ -47,12 +48,17 @@ end ``` - ```{julia} +#| eval: false a = input("Bitte 2 Zahlen eingeben!") ``` +```{julia} +#| echo: false +a = "34 56" +``` + ```{julia} av = split(a) ``` diff --git a/chapters/14_Plot.qmd b/chapters/14_Plot.qmd index f0f36ff..9d80592 100644 --- a/chapters/14_Plot.qmd +++ b/chapters/14_Plot.qmd @@ -28,11 +28,13 @@ Es gibt zahlreiche Grafikpakete für Julia. Zwei oft genutzte sind [Makie.jl](ht | [Luxor.jl](http://juliagraphics.github.io/Luxor.jl/stable/) |[Tutorial](https://juliagraphics.github.io/Luxor.jl/stable/tutorial/helloworld/)|[Examples](https://juliagraphics.github.io/Luxor.jl/stable/example/moreexamples/)| Allgemeine Vektorgrafik/Illustrationen | | [Javis.jl](https://juliaanimators.github.io/Javis.jl/stable/) |[Tutorials](https://juliaanimators.github.io/Javis.jl/stable/tutorials/)| [Examples](https://juliaanimators.github.io/Javis.jl/stable/examples/)| *Animierte* Vektorgrafik | [TidierPlots.jl](https://github.com/TidierOrg/TidierPlots.jl)| [Reference](https://tidierorg.github.io/TidierPlots.jl/latest/) || "is a 100% Julia implementation of the R package ggplot2 powered by Makie.jl"| -| [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl) | | [Examples](https://gist.github.com/gizmaa/7214002)| Interface zu Matplotlib (Python), 1:1-Übertragung der Python-API, deswegen s. [Matplotlib-Dokumentation](https://matplotlib.org/stable/) | +|[PythonPlot.jl](https://github.com/JuliaPy/PythonPlot.jl)| |[Examples (in Python)](https://matplotlib.org/stable/gallery/index.html)| Interface zu Matplotlib (Python), 1:1-Übertragung der Python-API, deswegen s. [Matplotlib-Dokumentation](https://matplotlib.org/stable/api/pyplot_summary.html) : {.striped .hover} - + ## Plots.jl @@ -95,6 +97,32 @@ savefig(plot1, "plot.png") Plot-Objekte können auch als Teilplot in andere Plots eingefügt werden, siehe Abschnitt @sec-subplot. + +### Funktionsplots + +Man kann `plot()` auch eine Funktion und einen Vektor mit $x$-Werten übergeben: + +```{julia} +# https://mzrg.com/math/graphs.shtml + +f(x) = abs(sin(x^x)/2^((x^x-π/2)/π)) + +plot(f, 0:0.01:3) +``` + + +Die parametrische Form $x = x(t),\ y = y(t)$ kann durch die Übergabe von zwei Funktionen und einen Vektor von $t$-Werten an `plot()` gezeichnet werden. + +```{julia} +# https://en.wikipedia.org/wiki/Butterfly_curve_(transcendental) + +xt(t) = sin(t) * (exp(cos(t))-2cos(4t)-sin(t/12)^5) +yt(t) = cos(t) * (exp(cos(t))-2cos(4t)-sin(t/12)^5) + +plot(xt, yt, 0:0.01:12π) +``` + + ### Plot-Themen > "PlotThemes is a package to spice up the plots made with Plots.jl."\ @@ -414,3 +442,36 @@ bar(cars.Model, cars.MPG, ``` + +### Was noch fehlt: Animation + +Hier sei auf die [Dokumentation](https://docs.juliaplots.org/latest/animations/) verwiesen und nur ein Beispiel +(von ) angegeben: + +```{julia} +#| error: false +#| warning: false +using Plots, Random +theme(:default) + +anim = @animate for i in 1:50 + Random.seed!(123) + scatter(cumsum(randn(i)), ms=i, lab="", alpha = 1 - i/50, + xlim=(0,50), ylim=(-5, 7)) +end + +gif(anim, fps=50) + +``` + + +:::: {.content-visible when-format="pdf"} +```{julia} +#| echo: false +Random.seed!(123) +i = 33 +scatter(cumsum(randn(i)), ms=i, lab="", alpha = 1 - i/50, + xlim=(0,50), ylim=(-5, 7)) + +``` +::::