Code Monkey home page Code Monkey logo

custompygraph's Introduction

Custompygraph

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.

Arguments

  • 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 and y data can be lists, numpy arrays, panda series or whatever matplotlib accepts as input.

Optional Arguments

  • 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.

Subplots

If you want to combine several subplots in one figure, you need to

  1. Initialize the figure first as a subplot and specify the number of rows and columns.
  2. Define each axis with make_plot, with subplot = True and subnum specified.
  3. 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()

Future extensions

  • allow an indefinite number of plots

custompygraph's People

Watchers

 avatar

custompygraph's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.