from_txt#

classmethod DataXY.from_txt(fname, data_layout='columns', idx_x=0, idx_y=1, title='', xlabel='', ylabel='', **loadtxt_kwargs)[source]#

Initiate DataXY from a text file.

The file is loaded using numpy.loadtxt().

Parameters:
fnamestr or PathLike

The filename.

data_layout“rows” or “columns”, default “columns”

Specify if centers and values are saved in the text file in rows or in columns.

idx_xint, default 0

The index that corresponds to the x values.

idx_yint, default 1

The index that corresponds to the y values.

titlestr, default “”

Optional title of the data.

xlabelstr, default “”

Optional x-label of the data.

ylabelstr, default “”

Optional y-label of the data.

Other Parameters:
**loadtxt_kwargs

Additional keyword arguments are passed to numpy.loadtxt().

Examples

Assume a data.txt with:

# data.txt
0.5    1
1.5    2
2.5    3
3.5    4
4.5    5

Initiate a histogram from it:

>>> data = ap.DataXY.from_txt("data.txt")
>>> data.x
array([1. 2. 3. 4. 5.])
>>> data.y
array([0. 1. 2. 3. 4. 5])

If multiple datasets are within one textfile, e.g.:

# manydata.txt
# y1   y2   x
  1         11        0.5
  2         12        1.5
  3         13        2.5
  4         14        3.5
  5         15        4.5

one can load specify which data to load using the idx_* keywords:

>>> data1 = ap.DataXY.from_txt("manydata.txt", idx_x=2, idx_y=0)
>>> data2 = ap.DataXY.from_txt("manydata.txt", idx_x=2, idx_y=1)
>>> data1.y
array([1. 2. 3. 4. 5.])
>>> data2.y
array([11. 12. 13. 14. 15.])