Last active
February 3, 2026 20:24
-
-
Save dacr/396592cd76e9cf9492ef5d0d26208ba9 to your computer and use it in GitHub Desktop.
plotting with chartreuse - photo count trend / published by https://github.com/dacr/code-examples-manager #fcc44436-bf5f-4bf2-9531-6656f9b6f7fa/a7f231a889e6d204cfc25e0213520de71433c2ad
This file contains hidden or 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
| // summary : plotting with chartreuse - photo count trend | |
| // keywords : chartreuse, plotting | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : fcc44436-bf5f-4bf2-9531-6656f9b6f7fa | |
| // created-on : 2024-08-21T16:42:51+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // attachments : data-taken-photos.csv | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "org.creativescala::chartreuse-core:0.2.0" | |
| // --------------------- | |
| import chartreuse.{*, given} | |
| import doodle.core.{Color, Point} | |
| import chartreuse.layout.* | |
| import java.time.{Instant, ZoneOffset} | |
| import scala.io.Source | |
| import cats.effect.unsafe.implicits.global | |
| import doodle.java2d.* | |
| import doodle.syntax.all.* | |
| val dataRE = """(\d+),(\d+)""".r | |
| val data = | |
| Source | |
| .fromFile("data-taken-photos.csv") | |
| .getLines() | |
| .collect { case dataRE(epoch, value) => Instant.ofEpochMilli(epoch.toLong).atOffset(ZoneOffset.UTC).getYear -> value.toInt } | |
| .toList | |
| .map((year, count) => Point(year, count)) | |
| val layout = | |
| Line | |
| .default[Point] | |
| .forThemeable(theme => | |
| theme | |
| .withStrokeWidth(3d) | |
| .withStrokeColor(Color.blue) | |
| ) | |
| val plot = | |
| layout | |
| .toPlot(data) | |
| .withPlotTitle("How many photos taken each year") | |
| .withXTitle("Year") | |
| .withYTitle("Photo count") | |
| val picture = plot.draw(800, 300) | |
| picture.draw() |
This file contains hidden or 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
| Taken photos each year | Count | |
|---|---|---|
| 1009839600000 | 1559 | |
| 1041375600000 | 1723 | |
| 1072911600000 | 1670 | |
| 1104534000000 | 1427 | |
| 1136070000000 | 3230 | |
| 1167606000000 | 3914 | |
| 1199142000000 | 3087 | |
| 1230764400000 | 3889 | |
| 1262300400000 | 4935 | |
| 1293836400000 | 5297 | |
| 1325372400000 | 5056 | |
| 1356994800000 | 5683 | |
| 1388530800000 | 5327 | |
| 1420066800000 | 2971 | |
| 1451602800000 | 2547 | |
| 1483225200000 | 4793 | |
| 1514761200000 | 5641 | |
| 1546297200000 | 7429 | |
| 1577833200000 | 4700 | |
| 1609455600000 | 4592 | |
| 1640991600000 | 5564 | |
| 1672527600000 | 6987 | |
| 1704063600000 | 11984 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment