Package: saneplot
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 defaultsHave all this code in one place and not scattered around multiple jupyter notebooksAll of the above allows to quickly create plots of 2d dimensional dataUsageEverything is done by the SanePlot class. The initialization parameters which control the plot are:figsize=(14.0,10.0)- the size of the plotlegendloc='upperright'- the legend locationlegend_frame_color='#FFFFFF'- color of the legend backgroundfontfamily='fantasy',font='Calibri'- these two parameters control the font. I only set them to use Cyrillic characterslegend_size=26- legend font sizetick_size=24- tick label sizexy_label_size=32- set the size of the X and Y axis labelstextsize=27- set the text sizelinewidth=5- the width of the curves being plottedmarkersize=5- the size of the markers being plottedxlim=None- either None or a tuple/list; if set, sets the X-limits of the plotylim=None- either None or a tuple/list; if set, sets the Y-limits of the plottext=None- either None or a string; if set, will place text somewhere on the plottext_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 anythingtext_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 anythinglog_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 tolog_x_baselog_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 tolog_y_basex_label=None- the label for the X axisy_label=None- the label for the Y axislinechange='monochrome'- sets the line styles. Can be eithermonochrome,coloror 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 thelabelparameter, 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.ExamplesThis can be inserted into a Jupyter notebook with%matplotlib inlineadded 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 history0.1 (01 February 2017) - first working version of the package created