From 894065fe9ccc0dd4b63d44af4dcfa21839135a37 Mon Sep 17 00:00:00 2001 From: froejdh_e Date: Wed, 9 Apr 2025 12:19:14 +0200 Subject: [PATCH] added utility plot --- python/aare/__init__.py | 2 +- python/aare/utils.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/python/aare/__init__.py b/python/aare/__init__.py index 606f958..98e8c72 100644 --- a/python/aare/__init__.py +++ b/python/aare/__init__.py @@ -17,7 +17,7 @@ from .CtbRawFile import CtbRawFile from .RawFile import RawFile from .ScanParameters import ScanParameters -from .utils import random_pixels, random_pixel, flat_list +from .utils import random_pixels, random_pixel, flat_list, add_colorbar #make functions available in the top level API diff --git a/python/aare/utils.py b/python/aare/utils.py index 4708921..a10f54c 100644 --- a/python/aare/utils.py +++ b/python/aare/utils.py @@ -1,4 +1,6 @@ import numpy as np +import matplotlib.pyplot as plt +from mpl_toolkits.axes_grid1 import make_axes_locatable def random_pixels(n_pixels, xmin=0, xmax=512, ymin=0, ymax=1024): """Return a list of random pixels. @@ -24,4 +26,11 @@ def random_pixel(xmin=0, xmax=512, ymin=0, ymax=1024): def flat_list(xss): """Flatten a list of lists.""" - return [x for xs in xss for x in xs] \ No newline at end of file + return [x for xs in xss for x in xs] + +def add_colorbar(ax, im, size="5%", pad=0.05): + """Add a colorbar with the same height as the image.""" + divider = make_axes_locatable(ax) + cax = divider.append_axes("right", size=size, pad=pad) + plt.colorbar(im, cax=cax) + return ax, im, cax \ No newline at end of file