Helpful Utilities

Set of useful utilities for plotting, and life in general!

pyspec.utils.makeNicePlot(ax, xint=5, yint=5, mxint=4, myint=4, tickcolor=None, framecolor=None, xformat=None, yformat=None)

Make nice plot by setting all border widths etc.

Designed to make a pedantic figure suitable for PRL, PRB etc. This function formats the border, tickmarks and sets the axes labels and titles to sensible values for ‘production’ quality plots.

xint : int
Number of x intervals for minor tics
yint : int
Number of y intervals for minor tics
xformat : string
Format string for major labels
yformat : string
Format string for minor labels
pyspec.utils.makePanelPlot(n=3, fig=None, xlmargin=0.15, ytmargin=0.1, xrmargin=0.05, ybmargin=0.1, ylabels=True)

Make a multi panel plot from matplotlib.

This function, makes a typical panel plot and returns a list of the axes objects for plotting.

n : int
Number of panels
fig : figure object
Figure object to use (If None creates new figure)
xmargin : float
Margin at x-axis
ymargin : float
Margin at y-axis
pyspec.utils.pickleit(filename, *args)

Pickle a python object

filename : string
Filename of file to pickle objects to.
args : list
List of python objects to pickle

This function can be used as a quick convenience function for pickling python objects. For example:

>>> a = 'hello'
>>> b = array([1, 2, 3, 4])
>>> c = SpecDataFile('myfile.01')
>>> pickleit('spam.pckl', a, b, c)
pyspec.utils.printAll(fname='Plot', hc=False, small=True, lpcommand='lp')

Print all figures

pyspec.utils.unpickleit(filename)

Unpickle a python object (created with pickleit)

filename : string
filename of file to unpickle.

This routine can be used to easily unpickle a file and serves as the companion to the :func:’pickle()’ function.

If only one python object is unpickled then that object is returned.

If multiple objects are pickled, then a list of these objects is returned.

pyspec.utils.writeString(filename, string, append=True)

Write a sring out to a file.

filename : string
Filename to write to.
string : string or object
String to write to file. If this is a python object then :func:’str()’ is called to make a string output.
append : bool
If true append text to file

Previous topic

Diffractometer

Next topic

Example code using pyspec

This Page