Created
December 15, 2022 13:42
-
-
Save titsuki/2d5f3c6b4aec7680e2346dc9fd84d3b6 to your computer and use it in GitHub Desktop.
example.raku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use Chart::Gnuplot; | |
use Chart::Gnuplot::Subset; | |
my $gnu = Chart::Gnuplot.new(:terminal("png"), :filename("a.png"), :writer( -> $msg { say $msg })); | |
my @data = (q:to/EOF/).split("\n", :skip-empty)>>.split(" ", :skip-empty); | |
Year Male Female | |
1950 100 90 | |
1960 100 90 | |
1970 80 70 | |
1980 130 140 | |
1990 140 120 | |
2000 200 210 | |
2010 240 230 | |
2020 400 420 | |
EOF | |
my ($header, *@body) = @data; | |
$gnu.command("set style histogram clustered"); | |
$gnu.legend(:left); | |
my AnyTicsTic @tics = (@body>>.[0]).pairs.map(-> (:key($pos), :value($year)) { %(:label($year), :pos($pos)) }); | |
$gnu.xtics(:tics(@tics)); | |
$gnu.xlabel(:label($header[0])); | |
$gnu.plot(:vertices(@body), :using([2]), :style("histogram"), :title($header[1]), :fill("solid 1.0"), :writer( -> $m\ | |
sg { say $msg })); | |
$gnu.plot(:vertices(@body), :using([3]), :style("histogram"), :title($header[2]), :fill("solid 1.0"), :writer( -> $m\ | |
sg { say $msg })); | |
$gnu.dispose; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment