hyperspy icon indicating copy to clipboard operation
hyperspy copied to clipboard

Line2DRoi for non-evenly spaced data

Open opens21 opened this issue 2 years ago • 1 comments

Describe the bug

The code below works for a 2D array which has evenly spaced data in x and y. The hyperspy plot functions is based on the matplotlib imshow function.

Is there any chance to use pcolormesh instead to account for unevenly spaced data? Or how can I circumvent this issue without using interpolation of my data?

To Reproduce

Steps to reproduce the behavior:

import hyperspy.api as hs
length = 100
y = 400
x = 0
width = 10

ima0.plot(cmap='seismic', aspect='auto', title='')
# what I would like to use instead in an interactive way:
# plt.pcolormesh(x,y,z,cmap='seismic')


plt.xlabel("")
plt.ylabel("")
plt.tight_layout()

line_roi = hs.roi.Line2DROI(x, y, x+length, y, width)
roi0 = line_roi.interactive(ima0)
ax2 = hs.plot.plot_spectra([roi0])
plt.xlabel("Position (nm)")
plt.ylabel("Phase (rad)")

opens21 avatar Dec 08 '23 12:12 opens21

Support for plotting 2D array with non-uniform have been added in 2.0 (release notes), which will be released before end of the year, however, the Line2DROI doesn't support non-uniform axes. It means that you will be able to plot images with non-uniform axes but not use the Line2DROI.

In 2.0, there is a new method (interpolate_on_axis) to convert non-uniform axis to uniform axis and you can that as a workaround to use Line2DROI after interpolation.

ericpre avatar Dec 10 '23 11:12 ericpre