From 1817cf2f5cbbd2793ec7171031ae80f8a0640bea Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Mon, 6 May 2024 03:22:36 -0400 Subject: [PATCH 1/3] Nix not very helpful geom_ name-space prefix in `GeomKind` enum strings. --- src/ggplotnim/ggplot_types.nim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ggplotnim/ggplot_types.nim b/src/ggplotnim/ggplot_types.nim index e8fa6c78..504c45d2 100644 --- a/src/ggplotnim/ggplot_types.nim +++ b/src/ggplotnim/ggplot_types.nim @@ -324,15 +324,15 @@ type bbSubset = "subset" GeomKind* = enum - gkPoint = "geom_point" - gkBar = "geom_bar" - gkHistogram = "geom_histogram" - gkFreqPoly = "geom_freqpoly" - gkTile = "geom_tile" - gkLine = "geom_line" - gkErrorBar = "geom_errorbar" - gkText = "geom_text" - gkRaster = "geom_raster" + gkPoint = "point" + gkBar = "bar" + gkHistogram = "histogram" + gkFreqPoly = "freqpoly" + gkTile = "tile" + gkLine = "line" + gkErrorBar = "errorbar" + gkText = "text" + gkRaster = "raster" HistogramDrawingStyle* = enum hdBars = "bars" ## draws historams by drawing individual bars right next to From d16a53ac2900a6b976d45b3440d66a1e032d2563 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 6 May 2024 11:28:02 +0200 Subject: [PATCH 2/3] update Vega-Lite backend geom mapping --- src/ggplotnim/ggplot_vega.nim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ggplotnim/ggplot_vega.nim b/src/ggplotnim/ggplot_vega.nim index 685f696d..9d29516f 100644 --- a/src/ggplotnim/ggplot_vega.nim +++ b/src/ggplotnim/ggplot_vega.nim @@ -11,16 +11,16 @@ const vegaLiteTmpl = """ """ let mapping = { "title" : "title" }.toTable -let geom_mapping = { "geom_point" : "point", - "geom_rect" : "rect", - "geom_line" : "line", - "geom_histogram" : "bar", - "geom_bar" : "bar", - "geom_freqpoly" : "line", - "geom_tile" : "rect", - "geom_text" : "text", - "geom_raster" : "rect", # or image?, - "geom_errorbar" : "errorbar" # non trivial because they are split in vega +let geom_mapping = { "point" : "point", + "rect" : "rect", + "line" : "line", + "histogram" : "bar", + "bar" : "bar", + "freqpoly" : "line", + "tile" : "rect", + "text" : "text", + "raster" : "rect", # or image?, + "errorbar" : "errorbar" # non trivial because they are split in vega }.toTable template toVegaField(f: string): string = From 7b9a4da2fdf2a652aa4a7c663eb876a3e3059d4b Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 6 May 2024 11:57:58 +0200 Subject: [PATCH 3/3] [recipes] update `col` reference syntax in Newton acc recipe --- recipes.org | 4 ++-- recipes/rNewtonAcceleration.nim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes.org b/recipes.org index 2ec5ae31..a5d6bfd3 100644 --- a/recipes.org +++ b/recipes.org @@ -2447,7 +2447,7 @@ This gives us two =seq[float]=, but we need a =DataFrame=. So we combine the two: #+BEGIN_SRC nim :tangle recipes/rNewtonAcceleration.nim var df = toDf({ "r / m" : radii, - "g(r) / m s¯²" : a}) + "g(r) / m s¯²" : a}) #+END_SRC which gives us a data frame with two columns. The names are, as one can guess, the given strings. (Note that in practice one might not want to @@ -2481,7 +2481,7 @@ At this point we might ask "Do we recover the known 9.81 m/s^2 at the surface?". Let's see. There's many different ways we could go on about this. We'll use summarize: #+BEGIN_SRC nim :tangle recipes/rNewtonAcceleration.nim -let maxG = df.summarize(f{float: "g_max" << max(c"g(r) / m s¯²")}) +let maxG = df.summarize(f{float: "g_max" << max(col("g(r) / m s¯²"))}) #+END_SRC An alternative way would be to access the data column directly, like diff --git a/recipes/rNewtonAcceleration.nim b/recipes/rNewtonAcceleration.nim index 63b7b6d0..60c059e1 100644 --- a/recipes/rNewtonAcceleration.nim +++ b/recipes/rNewtonAcceleration.nim @@ -19,7 +19,7 @@ let radii = linspace(0.0, 35_000_000, 1000) # up to geostationary orbit let a = radii.mapIt(newtonAcceleration(it)) var df = toDf({ "r / m" : radii, - "g(r) / m s¯²" : a}) + "g(r) / m s¯²" : a}) df = df.transmute(f{"r / km" ~ c"r / m" / 1000.0}, f{"g(r) / m s¯²"}) @@ -28,7 +28,7 @@ ggplot(df, aes("r / km", "g(r) / m s¯²")) + ggtitle("Gravitational acceleration of Earth depending on radial distance") + ggsave("media/recipes/rNewtonAcceleration.png") -let maxG = df.summarize(f{float: "g_max" << max(c"g(r) / m s¯²")}) +let maxG = df.summarize(f{float: "g_max" << max(col("g(r) / m s¯²"))}) let maxG_alt = df["g(r) / m s¯²"].toTensor(float).max