Custompygraph is a wrapper for matplotlib creating two-dimensional line plots which saves you the hassle of specifying each and every option (Labels, Titles, color, plot style, etc.) everytime you create the plot.
Everything is supposed to work through one call of make_plot()
, which might be appended with .show()
or .savefig()
. For subplots, the setting is slightly more complicated (see below).
The legend is put below the plot area instead of within, mimicking Stata style.
-
data expects a dictionary where each entry contains the label, and the x and y data as a list. The dictionary key will appear in the graph legend
Example:
data = {'label1': [x1data, y1data], 'label2': [x2data, y2data]}
x
andy
data can be lists, numpy arrays, panda series or whatever matplotlib accepts as input.
- xlab, ylab (str): abel for the respective axes
- title (str): the plot title
- fs (int): the basic font size applying to xlab and ylab (default=14). Legend labels will be a little smaller as well as tick labels; titles will be slightly larger.
- plottype (str): either "line" ( default ) or "scatter"
- xlim_low, xlim_high, ylim_low, ylim_high (int): limits of the two axes, respectively.
- lw (int): the linewidth for line plots (default=2).
- color (str):
=['bw', 'color']
specifies whether lines will be black or colored ( default: bw ). In the former case, lines will differ by linestyle (solid, dashed, dotted, ...) - showlegend (bool): [True (default), False]
- figs (tuple): Figure size. By default, the figure is built according to the golden ratio: figs = (8.09, 5)
- style (str): one of the styles from
print(plt.style.available)
. Careful: This option may override other settings on e.g. grid lines. - subplot (bool): If True, the function will return only the axis, not the whole plot. Requires subnum. See for subplots below.
- subnum (int): The position of the subplot. See for subplots below.
If you want to combine several subplots in one figure, you need to
- Initialize the figure first as a subplot and specify the number of rows and columns.
- Define each axis with make_plot, with subplot = True and subnum specified.
- Do whatever you like with the figure (show, savefig, etc.)
Example for a 1x2 Figure:
import matplotlib.pyplot as plt
from make_plot import make_plot
# 1. Initialize the plot
fig, (ax1, ax2) = plt.subplots(1,2)
# 2. Produce the axes
ax1 = make_plot(data=...,
title='Left Plot',
subplot=True,
subnum=121
)
ax2 = make_plot(data=...,
title='Right Plot',
subplot=True,
subnum=222
)
# 3. Output
fig.show()
- allow an indefinite number of plots