0

I want to show 3 projections of 3d numpy array side by side. A problem that projections have totally different sizes.

My current approach is next:

fig, axis = plt.subplots(nrows=2, ncols=2, squeeze=False, dpi=1)
fig.set_size_inches(p.shape[2] + p.shape[1], p.shape[0]+p.shape[1] )
axis[0, 0].imshow(getProjectionImageMean(p, minValue, maxValue, axis=1), cmap=plt.cm.gray)
axis[0, 1].imshow(getProjectionImageMean(p, minValue, maxValue, axis=2), cmap=plt.cm.gray)
axis[1, 0].imshow(getProjectionImageMean(p, minValue, maxValue, axis =0), cmap=plt.cm.gray)
for i in range(1):
    for k in range(2):
        axis[i, k].set_axis_off()
fig.subplots_adjust(wspace=0, hspace=0, top=1, bottom=0, left=0, right=1)
plt.savefig(OUTPUT_PATH + patient + "/projections.png", dpi=1)

The getProjectionImageMean is just a function that makes np.mean by some axis in the end.

Problem that projection can have next sizes, for example, (180, 1024), (180, 512) (512, 1024)

So I want the first column to be 2/3 of width. And first row to be 180/(180+512) of the height.

While matplotlib always give 1/n to every row and column.

Any workaround or even another library appreciated.

Thank you.

johngull
  • 819
  • 6
  • 22
  • 1
    Check out gridspec. https://matplotlib.org/users/gridspec.html Is this what you want? – tnknepp Feb 21 '18 at 15:56
  • @tnknepp thank you. That's close, I need to read it carefully to get if it matches. I had hope that there is some automatic solution which will calculate proportions of grid :) – johngull Feb 21 '18 at 16:03
  • Easy there. It is better to politely tell somebody they are wrong than to get them angry at you (especially if you turn out to be wrong). I think ImportanceOfBeingErnest's comment is correct since the linked answer is applicable here. It may not be EXACTLY what you were looking for, but you could probably figure something out from that post alone. – tnknepp Feb 21 '18 at 16:11

0 Answers0