silx
silx copied to clipboard
Image item with non linear axis normalization
I have this request for Flint https://gitlab.esrf.fr/bliss/bliss/-/issues/3398
I could use a scatter but the rendering will probably not be very good.
Any idea if we could imagine such item in silx?
In the meantime i will probably try to create an item to see what i could do with the existing tools.
For the record, here is the implementation i will use.
from silx.gui.plot.items.scatter import Scatter
class ImageWithNormalization(Scatter):
def __init__(self):
Scatter.__init__(self)
self.setVisualization(self.Visualization.IRREGULAR_GRID)
def setData(self, image, xAxis, yAxis, copy=True):
x = numpy.asarray(xAxis)
y = numpy.asarray(yAxis)
value = numpy.asarray(image)
assert x.ndim == 1
assert y.ndim == 1
assert value.ndim == 2
assert (y.shape[0], x.shape[0]) == value.shape
ax = numpy.broadcast_to(x, value.shape)
ay = numpy.broadcast_to(y.reshape(-1, 1), value.shape)
Scatter.setData(self, ax.flatten(), ay.flatten(), value.flatten())
self.setVisualizationParameter(
self.VisualizationParameter.GRID_SHAPE,
image.shape,
)
self.setVisualizationParameter(
self.VisualizationParameter.GRID_BOUNDS,
((x[0], y[0]), (x[-1], y[-1])),
)
self.setVisualizationParameter(
self.VisualizationParameter.GRID_MAJOR_ORDER, "row"
)
image = numpy.array([[1, 2, 3, 4], [3, 4, 5, 6]])
xAxis = numpy.array([1, 2.5, 3, 3.5])
yAxis = numpy.array([3, 4])
item = ImageWithNormalization(image, xAxis, yAxis)
Related to #4153