Skip to main content

Quickly and easily draw basic Lexis diagrams

Project description

PyLexis

PyLexis is a tool to easily plot Lexis Diagrams within Python. It is based on matplotlib and inspirated in LexisPlotR.

What is a Lexis Diagram?

In demography a Lexis diagram (named after economist and social scientist Wilhelm Lexis) is a two dimensional diagram that is used to represent events (such as births or deaths) that occur to individuals belonging to different cohorts. Calendar time is usually represented on the horizontal axis, while age is represented on the vertical axis. (https://en.wikipedia.org/wiki/Lexis_diagram)

Installation

pip install pylexis

Using PyLexis

First import the package and create a Diagram object with the following arguments:

initial year, final_year, first_age, last_age

import pylexis
diagram = pylexis.Diagram(1900, 1910, 0, 10)

This returns a basic diagram:

Then you have a few methods to interact with the graph:

Styling

  • pylexis.Diagram.set_font(size, weight): Set font size and weight.

      Parameters
      ----------
      size: int with font size in points (default 12, range[1-1000]).
      weight: str with font weight {'light', 'regular', 'book', 'medium', 'bold', 'heavy'}.
    
  • pylexis.Diagram.set_font_retroactively(size, weight): Idem set_font(). Use this to update the font after plotting and standardize the graph.

  • pylexis.Diagram.set_aspect(aspect): Set aspect ratio of the grid.

      Parameters
      ----------
      aspect: str or float with aspect ratio of the grid. Use 'square' for square cells, 'auto' for equal sized steps on both axes, or a float for a custom ratio.
    

Graphing Data

  • pylexis.Diagram.titles(x_label, y_label, title): Add title and axis labels.

  • pylexis.Diagram.lexis_fill(target, value, color, alpha): Highlight a certain age, year or cohort in the grid.

      Parameters
      ----------
      target: {'age', 'year' or 'cohort'}
      value: int with the value of the target selected.
      color: str with the colour to fill. Use 'random' to fill with a random color.
      alpha: float with the transparency of the fill. 0 is transparent, 1 is opaque.
    
  • pylexis.Diagram.add_births(year, value): Draw number of births in a specific year.

  • pylexis.Diagram.add_deaths(cohort, year, age, value): Draw number of deaths in a specific year for a specific cohort.

      Parameters
      ----------
      cohort: Year of the cohort.
      year: int with year of deaths.
      age: int with age at the time of deaths. Deaths can be before or after birthdays.
      value: int with the number of deaths.
    
  • pylexis.Diagram.add_text(year, age, value): Draw a free text in the grid.

      Parameters
      ----------
      year: int with year of the text point.
      age: int with age of the text point.
      value: string-castable value of the text point.
    
  • pylexis.Diagram.add_data(cohort, year, age, values): Add a list of data points to the Lexis Diagram.

      Parameters
      ----------
      cohort: list[int] with year of the cohorts 
      year: list[int] with years of deaths of each data points.
      age: list[int] with age of each data points.
      values: list of string-castable values of each data points.
    
  • pylexis.Diagram.add_data_unsafe(year, age, values): Idem add_data() without checking if the data fits in the grid.

      Parameters
      ----------
      year: list[int] with years of the data points.
      age: list[int] with age of the data points.
      values: list of string-castable values of the data points.
    

Export Data

  • pylexis.Diagram.save(filename): Save the Lexis Diagram as an image file.

      Parameters
      ----------
      filename: str with the name of the file to save.
    

Examples

Basic Diagram

Add Data Points and Texts

How to contribute to the project?

Please check the how to contribute instructions.

FAQ

Just ask me what you need!

Project details


Download files

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

Source Distribution

pylexis-0.1.3.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

pylexis-0.1.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pylexis-0.1.3.tar.gz.

File metadata

  • Download URL: pylexis-0.1.3.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pylexis-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bd62e86de39fa9a4ea33156f5847f8ef41f6a19c405114e78927aed76ce201cc
MD5 fb33d22f9045eecf7587a1e8bda5a73c
BLAKE2b-256 c6201fca1c0a4fcd7f011938fad2f4aa6837a6b8795ca694aeea05c12203e351

See more details on using hashes here.

File details

Details for the file pylexis-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pylexis-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pylexis-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0a990cc186cf823cf63419d350a0ed0f671efbadc09e6f38ea52287603005044
MD5 273036e1944e030e8f3ef976b42c6e84
BLAKE2b-256 75d6c942eb87b3c0e7a34e4836871736b54091c59986ed2d3b87675ff6ec9429

See more details on using hashes here.

Supported by

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