Skip to main content

Helper for matplotlib subplots.

Project description

showy

showy is a helper for matplotlib subplots.

Usage

showy can be used in a script-like manner.

Let's first define the layout:

layout = {
    "title": "Example",
    "graphs": [
        {
            "curves": [{"var": "sine_10"}],
            "x_var": "time",
            "y_label": "Fifi [mol/m³/s]",
            "x_label": "Time [s]",
            "title": "Sinus of frequency *"
        },
        {
            "curves": [{"var": "sine_30"}],
            "x_var": "time",
            "y_label": "This label is too long and will be truncated.",
            "x_label": "This label is too long and will be truncated.",
            "title": "This is a graph with a long title."
        },
        {
            "curves": [
                {
                    "var": "sine_100",
                    "legend": "origin",
                },
                {
                    "var": "sine_100p1",
                    "legend": "shifted",
                }
            ],
            "x_var": "time",
            "y_label": "Loulou [cow/mug]",
            "x_label": "Time [s]",
            "title": "Third graphg"
        }
    ],
    "figure_structure": [3, 1],
    "figure_dpi": 92.6,
    "width_label_legend": 20,
    "width_label_axes": 25,
    "width_label_plot": 30
}

Now, let's create dummy data:

import numpy as np

data = dict()
data["time"] = np.linspace(0, 0.1, num=256)

data["sine_10"] = np.cos(data["time"] * 10 * 2 * np.pi)
data["sine_30"] = np.cos(data["time"] * 30 * 2 * np.pi)
data["sine_100"] = np.cos(data["time"] * 100 * 2 * np.pi)
data["sine_100p1"] = 1. + np.cos(data["time"] * 100 * 2 * np.pi)

Finally, we just have to display it:

from showy import showy

showy(layout, data)

[!TIP] Define the layout in a yaml or json file in order to use it across applications.

If you define it in a yaml file, then load it with (need to install pyyaml:

import yaml

with open(filename, 'r') as file:
  layout = yaml.load(file, Loader=yaml.SafeLoader)

If you define it in a json file, then load it with:

import json

with open(filename, 'r') as file:
  layout = json.load(filename)

Using wildcard *

A neat feature of showy is the wild card usage to simplify layout creation. For example, if you have 3 variables called var_1, var_2, var_3, you only need to define the graph layout for a variable var_*.

The example above reduces to:

layout = {
    "title": "Example",
    "graphs": [{
        "curves": [{"var": "sine_*"}],
        "x_var": "time",
        "y_label": "Sine [mol/m³/s]",
        "x_label": "Time [s]",
        "title": "Sinus of frequency *"
    }],
    "figure_structure": [3, 3],
    "figure_dpi": 92.6
}

Using Plotly

Showy supports Matplotlib and Plotly to display your graphs. Default is set to Matplotlib. To use Plotly, add backend="plotly" when calling showy:

from showy import showy

showy(layout, data, backend="plotly")

This outputs an HTML file.

json-schema standard

showy is based on a json-schema standard defined here. Check this out to learn more about the usage of the json-schema standard. (For your daily usage of showy you just need to ensure your layout respects the schema)

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

showy-1.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

showy-1.1.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file showy-1.1.0.tar.gz.

File metadata

  • Download URL: showy-1.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for showy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 dc7542156634ec50d5b35fffb5fddb3e68d44d5015b1600a6cf0d710eb800b58
MD5 bcf291276b5fbf2f08fbfda8c90772fc
BLAKE2b-256 b5a930f45d54f736a80c7c5817a80682b1372cf300a91d338e2b8c402514e359

See more details on using hashes here.

File details

Details for the file showy-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: showy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for showy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46d4aba59e5bebefe9a6ee1074415ad6433aae921750e4bc0e32b491b32b7960
MD5 1993cdce731ba59b86b1f8fe96c90d54
BLAKE2b-256 82a86f8d310f321332812a2b118dee25b86e0b0bb84c06c877276c87617ef2bb

See more details on using hashes here.

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