Hello, I have made this subplots, here the images are in 4 columns, my idea is to compare them in a pair of two, that is, 1st column with 2nd and 3rd with 4th. But here it is bit confusing the way it looks right now. Is it possible to add a vertical line between 2nd and 3rd column somehow?? So that it seems like first two column are together and the other two are pairs? Is there any possible way to do it?
import matplotlib.pyplot as plt
indexes = [1000,1001]
indexes2 = [1010,1011]
columns = 4
rows = len(indexes)
f, axarr = plt.subplots(rows, columns,figsize=(10,10))
k = 0
for i in range(0, rows):
axarr[i, 0].set_title(str(indexes[k])+"-Patch 1",fontsize=15)
axarr[i, 1].set_title(str(indexes[k])+"-Patch 2",fontsize=15)
axarr[i, 2].set_title(str(indexes2[k])+"-Patch 1",fontsize=15)
axarr[i, 3].set_title(str(indexes2[k])+"-Patch 2",fontsize=15)
k = k+1
axarr[i, 0].set_xticks([])
axarr[i, 1].set_xticks([])
axarr[i, 0].set_yticks([])
axarr[i, 1].set_yticks([])
axarr[i, 2].set_xticks([])
axarr[i, 3].set_xticks([])
axarr[i, 2].set_yticks([])
axarr[i, 3].set_yticks([])
plt.tight_layout()
I have added the code how I got the subplots up. If it is helpful in answering the question. Thank you for your time. :)
If the question is not clear, I need a line like this, I added in image editor in the following image.

Adding a line is as easy as
line = plt.Line2D((.5,.5),(.1,.9), color="k", linewidth=3)
fig.add_artist(line)

import matplotlib.pyplot as plt
import numpy as np
a = np.random.rand(10,10,8)
columns = 4
rows = a.shape[2]//columns
fig, axarr = plt.subplots(rows, columns)
fig.subplots_adjust(left=0.1, right=0.9, wspace=0.4)
for i, ax in enumerate(axarr.flat):
img = a[:,:,i]
ax.imshow(img)
ax.set_title("-Patch {}".format(i))
line = plt.Line2D((.5,.5),(.1,.9), color="k", linewidth=3)
fig.add_artist(line)
plt.show()
For a more sophisticated solution with lines, see Draw a separator or lines between subplots
However, potentially you would rather adjust the spacing between the plots.
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import numpy as np
a = np.random.rand(10,10,8)
columns = 4
rows = a.shape[2]//columns
fig = plt.figure()
axarr1 = fig.subplots(2,2, gridspec_kw=dict(left=0.05, right=0.43, wspace=0.4))
axarr2 = fig.subplots(2,2, gridspec_kw=dict(left=0.57, right=0.95, wspace=0.4))
for i, ax in enumerate(axarr1.flat):
img = a[:,:,i]
ax.imshow(img)
ax.set_title("-Patch {}".format(i))
for i, ax in enumerate(axarr2.flat):
img = a[:,:,i+4]
ax.imshow(img)
ax.set_title("-Patch {}".format(i+4))
plt.show()
This allows to visually separate the two groups of subplots without having some black line in the plot.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With