Skip to main content

A Grammar of Graphics — one engine, spoken from Python

Project description

gog for Python

Draw a plot by describing it. You name a table, a shape to draw, and which column goes to which part of the picture. gog turns that description into an SVG.

One engine, written in Rust, does the drawing for R, Python, Julia and JavaScript. Each language writes the plot in its own idiom and gets back the same picture, to the byte.

Why you might want this

One vocabulary instead of a hundred chart types. There is no histogram() to look up, and no arguments that belong to it alone. The whole vocabulary fits on one page, and the combinations are the chart types: a histogram is bar * bin, a bar shape plus a binning statistic. Keep the statistic and change the shape, and the same counts draw a line, an area or a step. You learn the words once and they keep working.

It says no, and says what to write instead. Ask for something the grammar cannot mean and you get a refusal that names the fix. Nothing is accepted and then quietly dropped, so a plot that draws is a plot that means what you wrote.

The same picture from four languages. A colleague working in R, Julia or JavaScript writes the same sentence in their own idiom and gets the same file, to the byte. A team that does not share a language can still share a plot.

A plot is data, not code. What you build is a description that the engine draws, so it can be saved, compared, generated by another program, or sent over a network. That is awkward when a plot is a live object inside a session.

Things that usually need a second package are already here — three dimensions, animation, circular layouts, treemaps and contour maps are part of the same vocabulary rather than add-ons with a syntax of their own.

Install

pip install gog

The wheel carries the drawing engine, so there is nothing else to install and no Rust toolchain to set up.

Your first plot

from gog import *

gm = {"gdp": [1000, 8000, 30000],
      "life": [52, 68, 79],
      "continent": ["Africa", "Asia", "Europe"]}

(data(gm) + point + x(col.gdp, scale="log") + y(col.life)
 + color(col.continent)).save("life.svg")

Read that aloud: "Given gm: points, x is gdp on a log scale, y is life, color by continent." That is the whole idea. A plot is a sentence, and you can say it before you can write it.

A table is a dict of columns, or anything with .columns and df[name] — a pandas or polars frame works, and neither is required.

What you can draw

Shapes — points, lines, bars, areas, steps, error bars, boxes, ribbons, text, paths, reference lines, shaded regions, and surfaces in three dimensions.

Ways to show a column — position, color, size, shape, texture, transparency, or a split into one series per group.

Statistics, written into the sentence — binning, counting, sums, averages, medians, ranges, smoothing curves and density estimates. You do not calculate them beforehand.

Arrangements — small multiples in rows or columns, several plots on one page, a circular layout, a third dimension, and animation over a column.

There are no chart-type functions. A histogram is bar * bin, a pie is a bar chart in a circle, and a violin is a density drawn as a ribbon. Learn the words once and they combine.

When a plot cannot be drawn, gog says so and names what to write instead. It never quietly ignores part of what you asked for.

Two things Python needs

A column is col.name. Python has no bare names, and here a plain string is a value, as in style(color="tomato"). Writing x("gdp") is refused, with the correct spelling named. Use col["life exp"] for a name with a space in it.

from gog import * replaces five builtinsbin, sum, min, max and range are statistics here. If you need the originals in the same file, use import gog and write gog.point, or take one back with from builtins import sum.

Examples

The manual is a book, and every plot in it is drawn by the engine while the page is being built. Nothing in it is a screenshot.

https://psychometrician.github.io/gog-book/

It is written in R, and every sentence translates by the two rules above. The book's Python chapter is the difference list, about a page long.

License

Apache License 2.0. See LICENSE and NOTICE, which ship inside the package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gog-0.0.3-py3-none-win_amd64.whl (2.8 MB view details)

Uploaded Python 3Windows x86-64

gog-0.0.3-py3-none-manylinux_2_28_x86_64.whl (3.3 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

gog-0.0.3-py3-none-manylinux_2_28_aarch64.whl (3.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

gog-0.0.3-py3-none-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

gog-0.0.3-py3-none-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file gog-0.0.3-py3-none-win_amd64.whl.

File metadata

  • Download URL: gog-0.0.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gog-0.0.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1bf72c1048e061aff2800c0e2421f5eb8b7378ea43d40317f742265356cc4ed4
MD5 81461ec27f2994b5e55bbde75a869cae
BLAKE2b-256 c3f3166d9fa23cc55c265d57a882bf62723d49e1a3045d96370aab84ef820155

See more details on using hashes here.

Provenance

The following attestation bundles were made for gog-0.0.3-py3-none-win_amd64.whl:

Publisher: python-release.yml on psychometrician/gog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gog-0.0.3-py3-none-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: gog-0.0.3-py3-none-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gog-0.0.3-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4033e2937151aa58fac02ebc1f6b0d39b4470a2ed88067fdbbf2d50ef2f56a2b
MD5 0642a7413b0d30051535cbb72594b975
BLAKE2b-256 eb42f8facaa8da1986ffd06fa36de10bc4324eee57b6bf7f7e4fcb3ef5d419d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for gog-0.0.3-py3-none-manylinux_2_28_x86_64.whl:

Publisher: python-release.yml on psychometrician/gog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gog-0.0.3-py3-none-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: gog-0.0.3-py3-none-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: Python 3, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gog-0.0.3-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fde5685bdfb3ac18ef1925742f7ca6b668cc1e142e07d57b56d6da4156a75ab0
MD5 a1cb86ba6c6b1324431d7c26a26464fb
BLAKE2b-256 7888f505a5023a2921016a44215d64e663d13e6ce54b12b21465c309d3fdf966

See more details on using hashes here.

Provenance

The following attestation bundles were made for gog-0.0.3-py3-none-manylinux_2_28_aarch64.whl:

Publisher: python-release.yml on psychometrician/gog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gog-0.0.3-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: gog-0.0.3-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gog-0.0.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 96dbd709d4439b2ebfdb1f2f9f6c1b27c0dcdda2180dee13400d06afaa0ea7d8
MD5 47155e9636cd99ac96c502b107dc096a
BLAKE2b-256 187d3325d2760845ca10eacf3b00deccee0775dd80b31dfd630bb4b0525d6589

See more details on using hashes here.

Provenance

The following attestation bundles were made for gog-0.0.3-py3-none-macosx_11_0_arm64.whl:

Publisher: python-release.yml on psychometrician/gog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gog-0.0.3-py3-none-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: gog-0.0.3-py3-none-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: Python 3, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gog-0.0.3-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eb0b569e34d105011b4a19ca49b3694d40766ab6102ad2c7fc3844d4cb85615a
MD5 5ed3863167730ad82f3476d83dcabf3f
BLAKE2b-256 e0091e6d8720ffd43b7b7f2ce613fde7fcdfbdaf00ec353d2aa7b30a65f27bd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for gog-0.0.3-py3-none-macosx_10_12_x86_64.whl:

Publisher: python-release.yml on psychometrician/gog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page