0

I'm trying to create a figure with three subplots of a combined raster image and histogram. I found a class called seaborn_image with a function (seaborn_image.imghist) to plot an image and show the corresponding raster. However, I would like to plot three of these next to each other, but this turned out harder than it seemed.

The class does have this method to create subplots, but this does not work for the imghist objects. This gives the following error:

Traceback (most recent call last):

  File "/home/margot/Documents/code/plot_rasters.py", line 542, in <module>
    isns.ImageGrid(imghist_col)

  File "/home/margot/anaconda3/lib/python3.9/site-packages/seaborn_image/_grid.py", line 439, in __init__
    self._map_img_to_grid()

  File "/home/margot/anaconda3/lib/python3.9/site-packages/seaborn_image/_grid.py", line 496, in _map_img_to_grid
    if _d.ndim > 2:

AttributeError: 'Figure' object has no attribute 'ndim'

<Figure size 1440x504 with 0 Axes>

I also looked into using the SeabornFig2Grid class from this issue, using the following code:

fig = plt.figure(figsize=(20,7))
fig.subplots_adjust(top=1)
fig.suptitle('Crop rasters', fontsize=18)

nrows = 1
ncols = 3

imghist_s1 = isns.imghist(test_S1[test_key], aspect=2.2, cmap=batlow, dx=10, units='m') # pixelsize =10m
imghist_ndvi = isns.imghist(test_NDVI[test_key], aspect=2.2, vmin=0.1, vmax=0.95, cmap=batlow, dx=10, units='m') # pixelsize =10m
imghist_bp = isns.imghist(test_BP[test_key]/1000, aspect=2.2, vmin=0.1, vmax=0.95, cmap=batlow, dx=10, units='m') # pixelsize =10m

gs = gridspec.GridSpec(nrows, ncols)

mg0 = SeabornFig2Grid(imghist_s1, fig, gs[0])
mg1 = SeabornFig2Grid(imghist_s1, fig, gs[1])
mg2 = SeabornFig2Grid(imghist_s1, fig, gs[2])

gs.tight_layout(fig)
plt.show()

But this gives me the same error as was posted in this issue. Unfortunately, the given solution does not work for the seaborn_image class.

If this is not possible, I could also combine the images and histograms myself and then plot them as subplots. But I haven't found any suitable way to do this yet.

Can anyone help with the errors or does anyone have a suggestion how to approach the problem?

Anne0102
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 27 '22 at 14:21
  • You should do `fig, axs = plt.subplots(1, 3); isns.imghist(..., ax=axs[0],...)` etc – Jody Klymak Jul 27 '22 at 16:44
  • I tried this, but unfortunately it doesn't work with the `seaborn_image` package. I get `TypeError: seaborn_image._general.imgplot() got multiple values for keyword argument 'ax'` – Anne0102 Jul 28 '22 at 07:41

0 Answers0