added utility plot
All checks were successful
Build on RHEL9 / buildh (push) Successful in 1m48s

This commit is contained in:
froejdh_e 2025-04-09 12:19:14 +02:00
parent f16273a566
commit 894065fe9c
2 changed files with 11 additions and 2 deletions

View File

@ -17,7 +17,7 @@ from .CtbRawFile import CtbRawFile
from .RawFile import RawFile from .RawFile import RawFile
from .ScanParameters import ScanParameters 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 #make functions available in the top level API

View File

@ -1,4 +1,6 @@
import numpy as np 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): def random_pixels(n_pixels, xmin=0, xmax=512, ymin=0, ymax=1024):
"""Return a list of random pixels. """Return a list of random pixels.
@ -25,3 +27,10 @@ def random_pixel(xmin=0, xmax=512, ymin=0, ymax=1024):
def flat_list(xss): def flat_list(xss):
"""Flatten a list of lists.""" """Flatten a list of lists."""
return [x for xs in xss for x in xs] 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