I want python to display square images in any order like tiles.

Asked 2 years ago, Updated 2 years ago, 295 views

I think I'm erasing the gaps with wspace and hspace, but the image after execution has an unnatural gap

defketugou (path, outpath, zyunban, tate, yoko):
  
  d = [ ]

  for i in range (tate*yoko):
    img=Image.open(path+"/chunk_"+str(int(zyunban[i]))+".png")
    img=np.asarray(img)
    d.append(img)

  config,ax=plt.subplots(tate,yoko,figsize=(10,10)))
  config.subplots_adjust (wspace=0, hspace=0)

  for i in range(tate):
    for jin range (yoko):
      ax[i,j].xaxis.set_major_locator(plt.NullLocator())
      ax[i,j].yaxis.set_major_locator(plt.NullLocator())
      ax[i,j].imshow(d[yoko*i+j],cmap="bone")

  plt.savefig(outputpath, format=os.path.splitext(outputpath)[1][1:], dpi=360)
  print('finished')

python matplotlib

2022-09-30 21:55

1 Answers

You may be able to resolve this by adding aspect="auto" to the argument imshow.

According to the link above, aspect="equal" is drawn to guarantee an aspect ratio of 1.
This may create a 1-pixel gap when drawing.

Similar Questions for Home SO


2022-09-30 21:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.