Skip to main content

A simple plotting tool with sane default

Project description

A simple wrapper around some basic 2d matplotlib plotting which has some sane defaults. Developed mostly for personal use.


Motivation and use-cases:

  • Quickly set up multiple plot parameters (font sizes, text position, curve colors, x and y scales) without having to remember how to do that; provide some sane defaults

  • Have all this code in one place and not scattered around multiple jupyter notebooks

  • All of the above allows to quickly create plots of 2d dimensional data

Usage

Everything is done by the SanePlot class. The initialization parameters which control the plot are:

  • figsize=(14.0, 10.0) - the size of the plot

  • legendloc='upper right' - the legend location

  • legend_frame_color='#FFFFFF' - color of the legend background

  • fontfamily='fantasy', font='Calibri' - these two parameters control the font. I only set them to use Cyrillic characters

  • legend_size=26 - legend font size

  • tick_size=24 - tick label size

  • xy_label_size=32 - set the size of the X and Y axis labels

  • textsize=27 - set the text size

  • linewidth=5 - the width of the curves being plotted

  • markersize=5 - the size of the markers being plotted

  • xlim=None - either None or a tuple/list; if set, sets the X-limits of the plot

  • ylim=None - either None or a tuple/list; if set, sets the Y-limits of the plot

  • text=None - either None or a string; if set, will place text somewhere on the plot

  • text_x_rel=None - controls the relative X-position of the text (thus, a value of 0.5 will place the text in the middle of the plot with respect to the X-axis)

  • text_x_abs=None - controls the absolute X-position of the text. If text_x_rel is set, will not do anything

  • text_y_rel=None - controls the relative Y-position of the text (thus, a value of 0.5 will place the text in the middle of the plot with respect to the Y-axis)

  • text_y_abs=None - controls the absolute Y-position of the text. If text_x_rel is set, will not do anything

  • log_x_base=0 - if set to 0, the X axis is normal (linear). If different from 0, then the X axis is a log-axis with base equal to log_x_base

  • log_y_base=0 - if set to 0, the Y axis is normal (linear). If different from 0, then the X axis is a log-axis with base equal to log_y_base

  • x_label=None - the label for the X axis

  • y_label=None - the label for the Y axis

  • linechange='monochrome' - sets the line styles. Can be either monochrome, color or a list. If it is a list, curve number N on the plot will be plotted with a style set by the element number (N-1) % len(linechange) of the list. The list corresponding to 'monochrome': [‘k-’, ‘k–’, ‘ko’, ‘k^’, ‘k:’, ‘k*’] The list corresponding to 'color': [‘k’, ‘g’, ‘b’, ‘r’, ‘c’]

The methods are:

  • SanePlot.add_text(textsize=None) - adds text specified during the initialization. You can override the originally set textsize. Returns the Figure object.

  • SanePlot.plot(x, y, label=None, linewidth=None, markersize=None) - plots the curve specified by the (x,y) arrays. The label is set by the label parameter, and the originally set linewidth and markersize can be overridden. Returns the Figure object.

  • SanePlot.legend() - show the legend. Returns the Figure object.

  • SanePlot.show() - returns the Figure object.

Examples

This can be inserted into a Jupyter notebook with %matplotlib inline added and will show the resulting plots right there.:

import numpy as np
from saneplot import SanePlot

x = np.linspace(0, 30, 100)
y1 = np.sin(x) * 1000 + 4000
y2 = np.cos(x) * 1000 + 4000
y3 = x**2 * 1000

sp = SanePlot(x_label='x', y_label='y', text='(a)', text_x_abs=10, text_y_rel=0.5)

sp.plot(x, y1, '0')
sp.plot(x, y2+100, 'y2', linewidth=4)
sp.plot(x, y2+500, 'y2', linewidth=4)
sp.plot(x, y2+1000, 'y2', linewidth=3)
sp.plot(x, y2+2000, 'y2', linewidth=3)
sp.plot(x, y2+4000, 'y2', linewidth=4)
sp.plot(x, y2+8000, 'y2', linewidth=5)
sp.add_text(textsize=10)
sp.legend()

Version history

  • 0.1 (01 February 2017) - first working version of the package created

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

saneplot-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

saneplot-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file saneplot-0.1.0.tar.gz.

File metadata

  • Download URL: saneplot-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for saneplot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 596fe5a31e1cea3fcfa5b471613f2de3e8a4aee882417a09f192bd8e40420c13
MD5 72ebc70335b81b3da3715ba673fc03e0
BLAKE2b-256 e5fc498579696047b4a236e0cdd44628771ab025942bb01d282c718fd6028573

See more details on using hashes here.

File details

Details for the file saneplot-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for saneplot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5dff96d9ec21a9f1d986ff792cb5191ebb69853e1ee5a22963d91c45ec8e7abe
MD5 60875ef27a68926c806fcbf4afd66e69
BLAKE2b-256 400c541edc4296adaa4da382364d51e8de9f8abfc8f2d5fabbe53469148fdf66

See more details on using hashes here.

Supported by

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