1

enter image description here

Does anyone know how I can make a plot like the one shown above? I know how to make the plot after the 2 rows, but I'm not sure how I can add a vertical separator and then another 2 rows above it, as shown above.

By the way, I'm only referring to the STRUCTURE of the plot and not of the content.

Here's the code I can use for the portion after the first 2 rows:

import matplotlib.pyplot as plt
import numpy as np
f, axarr = plt.subplots(nrows=10, ncols=10,
                                figsize=(4,4),
                                gridspec_kw={'hspace': 0, 'wspace': 0})
for dim in range(10):
    samples = np.random.rand(10, 256, 256, 1)
    for sample_idx in range(10):
        axarr[dim][sample_idx].imshow(samples[sample_idx,:,:,0],
                                             cmap='gray')
        axarr[dim][sample_idx].set_axis_off()
plt.subplots_adjust(wspace=0.1, hspace=0.1, left=0, right=1, bottom=0, top=1)
plt.show()

EDIT: I've tried some of the suggested solutions and here is what I got:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec

plt.subplots_adjust(hspace=0.01)

outer = gridspec.GridSpec(2, 1, height_ratios = [2, 10], hspace=.2)

gs1 = gridspec.GridSpecFromSubplotSpec(2, 10, subplot_spec=outer[0], hspace=0.01)
gs2 = gridspec.GridSpecFromSubplotSpec(10, 10, subplot_spec=outer[1], hspace=0.01)

for i in range(2):
    for j in range(10):
        ax = plt.subplot(gs1[i,j])
        ax.plot()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

for i in range(10):
    for j in range(10):
        ax = plt.subplot(gs2[i,j])
        ax.plot()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
plt.show()

enter image description here

Overall, the structure is what I want but how can I get rid of those dark black lines in the 3 rows?

cmed123
  • 675
  • 6
  • 18
  • Would this solve your problem? https://stackoverflow.com/questions/31484273/spacing-between-some-subplots-but-not-all/31485288 – Carlo Alberto May 31 '20 at 07:42
  • Does this answer your question? [Spacing between some subplots but not all](https://stackoverflow.com/questions/31484273/spacing-between-some-subplots-but-not-all) – Ch3steR May 31 '20 at 07:51
  • @Ch3steR thank you! I've edited my question with what you suggested. do you know how i can get rid of those dark lines though? – cmed123 May 31 '20 at 08:09
  • @CarloAlberto thank you! I've edited my question with what you suggested. do you know how i can get rid of those dark lines though? – cmed123 May 31 '20 at 08:09
  • Off-topic @cmed123: Take a look at learning how to write 'dry' code in python, I guess it applies to comments here as well ;) – Mandera May 31 '20 at 08:23
  • Isn't this out of control as increasing the size of the graph will result in thick lines in different places? You have set `hspace=0.01`, but why don't you make it a minimum gap? – r-beginners May 31 '20 at 08:50
  • @r-beginners what do you mean by make it a minimum gap? – cmed123 May 31 '20 at 08:51
  • I think some of the overlapping thick lines are caused by graphs and graphs overlapping, so I guess I'll just have to space them out at a minimum. – r-beginners May 31 '20 at 09:50

1 Answers1

0

Regarding to the overlapped lines, I tried with hspace=0.001 and it seems they are gone.

gs2 = gridspec.GridSpecFromSubplotSpec(10, 10, subplot_spec=outer[1], hspace=0.001)

enter image description here

To remove space between columns try with wspace=0.

gs1 = gridspec.GridSpecFromSubplotSpec(2, 10, subplot_spec=outer[0], hspace=0.01, wspace=0)
gs2 = gridspec.GridSpecFromSubplotSpec(10, 10, subplot_spec=outer[1], hspace=0.001, wspace=0)

enter image description here

Marcos
  • 786
  • 7
  • 8
  • Hmm ok thank you. I'm still trying to see if I can get it formatted the same way my original picture in the question is formatted. With the way this is, there's no vertical spacing between the cells – cmed123 May 31 '20 at 19:45