#!/usr/bin/env python3 """make_example_fig.py Example research figure (matplotlib). EXAMPLE DATA. The numbers below are made up to show the house style. Replace them with a source-backed series and name the source in the LaTeX caption. Writes example_fig.pdf (vector, for LaTeX) and example_fig.png (decks, previews). Run from anywhere: python3 figures/make_example_fig.py """ from pathlib import Path import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np HERE = Path(__file__).resolve().parent STYLE = HERE.parent / "ima-research.mplstyle" plt.style.use(str(STYLE)) NAVY = "#0B1622" SKY = "#C5D4E2" CYAN = "#4EC3E0" MUTED = "#5A6572" LINE = "#CDD5DD" # EXAMPLE DATA (not real) labels = ["Item A", "Item B", "Item C", "Item D", "Item E", "Item F"] scores = [22, 19, 17, 14, 11, 8] def main(): y = np.arange(len(labels))[::-1] colors = [NAVY] * 3 + [SKY] * 3 colors[0] = CYAN # one highlight, small accent only fig, ax = plt.subplots(figsize=(6.2, 3.4)) for xv in (5, 10, 15, 20, 25): ax.axvline(xv, color=LINE, lw=0.5, zorder=0) ax.barh(y, scores, height=0.55, color=colors, zorder=2) for yi, s in zip(y, scores): ax.text(s + 0.4, yi, str(s), ha="left", va="center", fontsize=8) ax.set_yticks(y) ax.set_yticklabels(labels) ax.set_xlabel("Composite score (max 25)") ax.set_xlim(0, 28) ax.set_ylim(-0.6, len(labels) - 0.4) ax.text(27.8, -0.55, "EXAMPLE DATA", ha="right", va="bottom", fontsize=7, color=MUTED) fig.savefig(HERE / "example_fig.pdf") fig.savefig(HERE / "example_fig.png", dpi=150) plt.close(fig) print("wrote example_fig.pdf, example_fig.png") if __name__ == "__main__": main()