<!-- DO NOT EDIT. -->
<!-- THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. -->
<!-- TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: -->
<!-- "auto_examples/readers_writers/plot_correlated_averages_reader.py" -->
<!-- LINE NUMBERS ARE GIVEN BELOW. -->

#### NOTE
[Go to the end](#sphx-glr-download-auto-examples-readers-writers-plot-correlated-averages-reader-py)
to download the full example code.

<a id="sphx-glr-auto-examples-readers-writers-plot-correlated-averages-reader-py"></a>

# Correlated Averages Reader

Read correlation functions from `fix ave/correlate` and `fix ave/correlate/long` commands.

<!-- GENERATED FROM PYTHON SOURCE LINES 8-40 -->
```Python
import os
from pathlib import Path

from pylimer_tools.io.read_lammps_output_file import read_correlation_file


def _find_fixtures_dir() -> Path:
    for cur in (
        [Path(__file__).resolve().parent] if "__file__" in globals() else []
    ) + [Path.cwd()]:
        for p in [cur] + list(cur.parents):
            candidate = p / "tests" / "pylimer_tools" / "fixtures"
            if candidate.is_dir():
                return candidate
    return Path("tests/pylimer_tools/fixtures").resolve()


_fixtures_dir = _find_fixtures_dir()
correlation_file = str(_fixtures_dir / "example_correlation_file.out.corr.txt")

# Read correlation data
correlation_data = read_correlation_file(correlation_file)

# Access correlation data by timestep
last_timestep = correlation_data["Timestep"].max()
last_correlation = correlation_data[correlation_data["Timestep"]
                                    == last_timestep]

_ = last_correlation.plot(
    x="Time", y=[
        "c_pA1*c_pA1", "c_pA2*c_pA2", "c_pA3*c_pA3"])
```

**Total running time of the script:** (0 minutes 0.039 seconds)

<a id="sphx-glr-download-auto-examples-readers-writers-plot-correlated-averages-reader-py"></a>

[`Download Jupyter notebook: plot_correlated_averages_reader.ipynb`](_downloads/8f9e1e246ad9272ddda4d7b833e56292/plot_correlated_averages_reader.ipynb)

[`Download Python source code: plot_correlated_averages_reader.py`](_downloads/ace4b682c05b4218a0ed73805ec74869/plot_correlated_averages_reader.py)

[`Download zipped: plot_correlated_averages_reader.zip`](_downloads/7b8165985d3db9c41f71bfc85c9ec94c/plot_correlated_averages_reader.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
