Skip to main content

Useful methods for plots used in science

Project description

Scientific Plots

Create and save plots in scientific style

Table of Contents

[[TOC]]

Overview

This python module includes useful methods and definitions for various python projects. The focus lies of on the automatic creation of a set of plots, which are designed to be used in scientific journals, dissertations and presentations. The most important components are the definitions of types compatible for numpy, located in types_.py, and the typing stubs in stubs/. These typing stubs are also distributed in this package.

Plotting

The easiest way to implement the plotting features provided by this library, is to use one of the predefined function in scientific_plots.default_plots. Alternatively, any plotting functions can be decorated by using the apply_styles decorator in scientific_plots.plot_settings.

For example, this could look like this:

import matplotlib.pyplot as plt
from scientific_plots.plot_settings import apply_styles

@apply_styles
def plot_something() -> None:
    """Example function."""
    plt.plot(...)
    ...
    plt.savefig("subfolder/your_plot_name.pdf")

The script will create a bunch of plots and place them in the given location next to your given path. Thus, it is advisable to create a different subfolder for new plots.

For three-dimensional plots, it is recommended to set the optional argument three_d of the decorator to true:

@apply_styles(three_d=True)
def plot_function():
    ...

Alternatively, this package provides default plot settings in the submodule default_plots. The provided function apply a default design, which should look good in most situations.

from scientific_plots.default_plots import plot

plot(x, y, "x_label", "y_label", "subfolder/filename.pdf")

Besides this simple plot, this library also provides the following default plots: plot_fit: Plot data and a fit of this data.

def fit_function(x):
    ...
    # fit some data
    ...
    return y

plot_fit(
    x, y, fit_function, "x_label", "y_label",
    "subfolder"/"filename.pdf")`

two_plots: Plot two curves sharing a single y-axis.

two_plots(
    x1, y1, "label1",
    x2, y2, "label2",
    "xlabel", "ylabel", "subfolder"/"filename".pdf)

two_axis_plots: Plot two curves with two y-axis in a single graph.

two_axis_plots(
    x1, y1, "label1",
    x2, y2, "label2",
    "xlabel", "ylabel1", "ylabel2",
    "subfolder"/"filename".pdf)

All of those functions have the following command-line arguments:

  • logscale: Plot the data double logarithmic.
  • single_log: Plot the x-axis logarithmic.
  • single_log_y: Plot the y-axis logarithmic.
  • xlim: Set the limits on the x-axis manually.
  • ylim: Set the limits on the y-axis manually.

Preview-Mode

It is possible to only create a single plot for every called plot function to save computation time. This 'preview' mode can be called by setting the following global variable in scientific_plots.plot_settings to true:

import scientifc_plots.plot_settings
scientifc_plots.plot_settings.PREVIEW = True

Types

Additional Vector like types for numpy-arrays are provided in scientifc_plots.types_. These types can be used for static type checking using mypy.

Typing Stubs

Addtional typing stubs for scipy, matplotlib and numba are provided and installed by this package. These packages do not provide type hints on their own.

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

scientific_plots-1.9.5.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

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

scientific_plots-1.9.5-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file scientific_plots-1.9.5.tar.gz.

File metadata

  • Download URL: scientific_plots-1.9.5.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for scientific_plots-1.9.5.tar.gz
Algorithm Hash digest
SHA256 7f4a6647d341a898c178c3c4f6f51a375a4d39e9f7d9b9346294aeb2d2245184
MD5 ebb758a09b207f224946ada3b1e4d4ca
BLAKE2b-256 b00b03484e204257f82f89001c92acf3b06e509a4c59e5cd30f586125d660929

See more details on using hashes here.

File details

Details for the file scientific_plots-1.9.5-py3-none-any.whl.

File metadata

File hashes

Hashes for scientific_plots-1.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2a764406d78b5232a8b4b1293e66109a7cd6c801dba70bef7c059f566500cb7d
MD5 6c1f0b3fbbeaaad5fb3566444250a283
BLAKE2b-256 301d1e32b38fa5254d54be0a90d4d1af38cd57809a05f202ce168d21e060cbf0

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