From fc9fc4022f15a425c7b2d92c406ff142e88d8fec Mon Sep 17 00:00:00 2001 From: erentar Date: Fri, 21 Jun 2024 02:03:27 +0200 Subject: [PATCH 1/3] Add plot demo using plotutils --- demos/plot.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 demos/plot.sh diff --git a/demos/plot.sh b/demos/plot.sh new file mode 100755 index 0000000..e33679b --- /dev/null +++ b/demos/plot.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# erentar2002 2024 + +# This script plots certain properties of elements on the periodic table + +# Dependency: gnu plotutils https://pkgs.org/search/?q=plotutils + +# To display the plot, use ./tek4010 demos/plot.sh + +# From top to bottom: +# - curl: download the periodic table data +# source: https://gist.github.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee +# +# - awk: split file by seperator "," +# then filter missing values in column 20 (density) +# then filter up to element 105 +# then print atomic mass and density +# +# - sed: remove the top row which includes names +# +# - graph: -X x axis title; +# -Y y axis title; +# -F font; +# -m line type; +# -S symbol type and size; +# -w width; +# -r move horizontally +# +# - plot: -T use tek device +curl 'https://gist.githubusercontent.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee/raw/1d92663004489a5b6926e944c1b3d9ec5c40900e/Periodic%2520Table%2520of%2520Elements.csv' \ +| awk '{split($0,a,","); if(length(a[20])!=0&&a[4]<105){print a[4],a[20]}}' | \ +sed 1d \ +| graph -X "atomic mass" -Y "density" -F "HersheySans" -m 1 -S 2 0.03 -w 1 -r 0 \ +| plot -T tek + +# On the line containing `awk`, columns are selected at the print statement. +# This script selects the 4th and 20th columns, which are atomic mass and density respectively. + +# Full documentation for the `graph` utility is available at https://www.gnu.org/software/plotutils/manual/en/plotutils.pdf From dfdc384bd56d5645fc242d35b7d2b4cba39c5313 Mon Sep 17 00:00:00 2001 From: erentar Date: Fri, 21 Jun 2024 12:42:45 +0200 Subject: [PATCH 2/3] Changes to accommodate repo owner requests --- demos/{ => plotutils}/plot.sh | 3 ++- demos/plotutils/readme | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) rename demos/{ => plotutils}/plot.sh (90%) create mode 100644 demos/plotutils/readme diff --git a/demos/plot.sh b/demos/plotutils/plot.sh similarity index 90% rename from demos/plot.sh rename to demos/plotutils/plot.sh index e33679b..740ab59 100755 --- a/demos/plot.sh +++ b/demos/plotutils/plot.sh @@ -4,8 +4,9 @@ # This script plots certain properties of elements on the periodic table # Dependency: gnu plotutils https://pkgs.org/search/?q=plotutils +# This package can be installed by running `apt install plotutils` on debian and its derivatives -# To display the plot, use ./tek4010 demos/plot.sh +# To display the plot, use ./tek4010 demos/plotuils/plot.sh # From top to bottom: # - curl: download the periodic table data diff --git a/demos/plotutils/readme b/demos/plotutils/readme new file mode 100644 index 0000000..f0718fe --- /dev/null +++ b/demos/plotutils/readme @@ -0,0 +1,4 @@ +This directory contains a plot demo using GNU plotutils. + +GNU plotutils is available on most linux distributions as `plotutils`. +On Raspberry Pi OS and other Debian derivatives, this package can be installed by `apt install plotutils`. From 80863fec0ba8bc66b1441e71e0b4bdcf8afed040 Mon Sep 17 00:00:00 2001 From: erentar Date: Fri, 21 Jun 2024 17:21:17 +0200 Subject: [PATCH 3/3] improvement to the plot and to the script --- demos/plotutils/plot.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/demos/plotutils/plot.sh b/demos/plotutils/plot.sh index 740ab59..87cc8ef 100755 --- a/demos/plotutils/plot.sh +++ b/demos/plotutils/plot.sh @@ -13,13 +13,13 @@ # source: https://gist.github.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee # # - awk: split file by seperator "," -# then filter missing values in column 20 (density) -# then filter up to element 105 -# then print atomic mass and density +# then filter missing values +# then print atomic mass, then density multiplied by atomic radius # # - sed: remove the top row which includes names # -# - graph: -X x axis title; +# - graph: -L plot title +# -X x axis title; # -Y y axis title; # -F font; # -m line type; @@ -28,10 +28,24 @@ # -r move horizontally # # - plot: -T use tek device -curl 'https://gist.githubusercontent.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee/raw/1d92663004489a5b6926e944c1b3d9ec5c40900e/Periodic%2520Table%2520of%2520Elements.csv' \ -| awk '{split($0,a,","); if(length(a[20])!=0&&a[4]<105){print a[4],a[20]}}' | \ -sed 1d \ -| graph -X "atomic mass" -Y "density" -F "HersheySans" -m 1 -S 2 0.03 -w 1 -r 0 \ +curl -s 'https://gist.githubusercontent.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee/raw/1d92663004489a5b6926e944c1b3d9ec5c40900e/Periodic%2520Table%2520of%2520Elements.csv' \ +| awk \ + '{ + split($0,a,","); + if(a[4]*a[20]*a[17]){ # discard rows with missing columns + print a[1],a[20]*a[17] + } + }' \ +| sed 1d \ +| graph \ + -L "Density of elements" \ + -X "atomic number" \ + -Y "density(g/cm^3) * atomic radius(rcovH)" \ + -F "HersheySans" \ + -m 2 \ + -S 3 0.03 \ + -w 1 \ + -r 0 \ | plot -T tek # On the line containing `awk`, columns are selected at the print statement.