Skip to content

A simple matplotlib wrapper to avoid writing multiple plt. statements.

License

Notifications You must be signed in to change notification settings

kvgc153/beautifyPlot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

beautifyPlot

A simple matplotlib wrapper to avoid writing multiple plt. statements.

Installation

pip install beautifyPlot

Usage

matplotlib code:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,100,1)
y = x**3

plt.plot(x,y,label='y=f(x)')
plt.title("test plot")
plt.xlim([0,10])
plt.ylim([0,1000])
plt.legend(fontsize=15)
plt.tight_layout()

Using beautifyPlot

from beautifyPlot.bplt import beautifyPlot
import numpy as np
x = np.arange(0,100,1)
y = x**3

plt.plot(x,y,label='y=f(x)')

plotArgs = {
    'title'           : ['test plot'], ## Use list to pass a set of arguments to the function
    'xlim'            : [0,10],
    'ylim'            : [0,1000],
    'legend'          : {'fontsize':15, 'loc':'best'}, ## Use dictionary to specify arguments
    'tight_layout'    : [] ## Leave list empty if there is nothing to pass
}
beautifyPlot(plotArgs)

## Next steps: Save plotArgs as JSON or use the same plot arguments in a different subplot/plot.

Using beautifyPlot (with shorthand notation)

from beautifyPlot.bplt import beautifyPlot
import numpy as np
x = np.arange(0,100,1)
y = x**3

plt.plot(x,y,label='y=f(x)')

plotArgs ={
    't'   : ['test plot'],
    'xl'  : [0,10],
    'yl'  : [0,1000],
    'l'   : {'fontsize':15, 'loc':'best'},
    't_l' : []
}
beautifyPlot(plotArgs)

Built-in shorthand notations

shorthand command
"l" plt.legend
"t_p" plt.tick_params
"t_l" plt.tight_layout
"t" plt.title
"xl" plt.xlim
"yl" plt.ylim
"xt" plt.xticks
"yt" plt.yticks
"xlab" plt.xlabel
"ylab" plt.ylabel
"xs" plt.xscale
"ys" plt.yscale

About

A simple matplotlib wrapper to avoid writing multiple plt. statements.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages