atompy.load_2d_from_txt#
- atompy.load_2d_from_txt(fname, output_format='pcolormesh', xyz_indices=(1, 0, 2), permuting='x', xmin=None, xmax=None, ymin=None, ymax=None, origin=None, **loadtxt_kwargs)[source]#
Load 2D data stored in a text file.
Three columns in the file should specify the x, y, and corresponding z values of the data. E.g.,
y0 x0 z00 y0 x1 z01 y0 x2 z02 ... y0 xN z0N y1 x0 z10 ... yM xN zMN
You can specify which value is permuting first (in the example above
x) with the permuting keyword. The assignment of the columns (here, y, x, z) is specified by the xyz_indices keyword.- Parameters:
- fname
str Filename, including filetype.
- output_format{
"imshow","pcolormesh","Hist2d"}, default"pcolormesh" Change output format. See Returns.
- xyz_indices(
int,int,int), default (1, 0, 2) Specify which column in the file corresponds to x, y, z.
The default corresponds to the output format of the default ROOT macro of the Atomic Physics group that exports 2D data to a text file (
hist2ascii).- permuting{
"x","y"}, default"x" Specify if the x- or y-column permutes through the values first.
- xmin, ymin
float, optional Specify the lower x (y) limit of the data in fname. Only necessary if the x (y) values in fname are not equally spaced. Alternatively, specify xmax (ymax.
- xmax, ymax
float, optional Specify the upper x (y) limit of the data in fname. Only necessary if the x (y) values in fname are not equally spaced. Alternatively, specify xmin (ymin). If xmin (ymin) and xmax (ymin) are specified, xmax (ymax) is not used.
- origin{
"lower","upper"}, optional Specify the origin of the imshow-image. If
None, useplt.rcParams["image.origin"].- **loadtxt_kwargs
Other
numpy.loadtxt()keyword arguments. Useful if, e.g., you want to skip a certain number of lines in the text file.
- fname
- Returns:
- output
PcolormeshData,ImshowDataorHist2d Depends on output_format.
output_format == "pcolormesh": ReturnPcolormeshData.output_format == "imshow": ReturnImshowData.output_format == "Hist2d": Return aHist2d.
- output
Examples
Load data such that it can be plotted using
matplotlib.pyplot.pcolormesh().data = ap.load_2d_from_txt("data.txt", output_format="pcolormesh") plt.pcolormesh(data.x, data.y, data.z)
Load data such that it can be plotted using
matplotlib.pyplot.imshow().data = ap.load_2d_from_txt("data.txt", output_format="imshow") plt.imshow(data.image, extent=data.extent)
Alternatively, immediately unpack the loaded data into their respective
numpy.ndarray.x, y, z = ap.load_2d_from_txt("data.txt", output_format="pcolormesh") plt.pcolormesh(x, y, z) image, extent = ap.load_2d_from_txt("data.txt", output_format="imshow") plt.imshow(image, extent=extent)
Load data as a
Hist2d".hist = ap.load_2d_from_txt("data.txt", output_format="Hist2d") data = hist.column_normalized_to_sum.for_pcolormesh plt.pcolormesh(data.x, data.y, data.z)