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

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

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

# Histogram Reader

Process histogram data from `fix ave/hist` commands.

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

import matplotlib.pyplot as plt

from pylimer_tools.io.read_lammps_output_file import read_histogram_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()
file_path = str(_fixtures_dir / "example_vec_avg_file.out.vec-avg.txt")

# Read histogram data
histogram_data = read_histogram_file(file_path)

# Plot histogram for specific timestep
final_timestep = histogram_data["TimeStep"].max()
final_hist = histogram_data[histogram_data["TimeStep"] == final_timestep]

plt.bar(final_hist["value1"], final_hist["value2"])
plt.xlabel("Density")
plt.ylabel("Frequency")
plt.title(f"Density Distribution at Step {final_timestep}")
plt.show()
```

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

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

[`Download Jupyter notebook: plot_histogram_reader.ipynb`](_downloads/54df38eea270585db2ec7b1801395a93/plot_histogram_reader.ipynb)

[`Download Python source code: plot_histogram_reader.py`](_downloads/ebae07b82414b668f5b1764b0f2e9018/plot_histogram_reader.py)

[`Download zipped: plot_histogram_reader.zip`](_downloads/28310ce5f0f5fec9e023173e9115c953/plot_histogram_reader.zip)

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