5

The second subplot is just the first image with an overlay ploted. In the second plot there appears to have white padding/boarder. How do I remove this padding/whitespace?

enter image description here

For completness, here is the fragment of code that performs the plotting:

fig, ax = plt.subplots(1, 2)
fig.set_size_inches(16, 6, forward=True)
plt.subplots_adjust(0.05, 0.05, 0.95, 0.95, 0.05, 0.05)
ax[0].set_title("Region Labels")
ax[0].imshow(image_labels)

ax[1].set_title("Region Connectivity Graph")
ax[1].imshow(image_labels)
for edge in edges:
    ax[1].plot([centers[edge[0]][0],centers[edge[1]][0]],
             [centers[edge[0]][1],centers[edge[1]][1]]) 
for a in ax:
    a.set_xticks(())
    a.set_yticks(())
plt.show()
Cœur
  • 37,241
  • 25
  • 195
  • 267
Michael
  • 559
  • 6
  • 15

1 Answers1

6

By default, Matplotlib adds some margin to plotted data. I cant test it because it dont have your image_labels and centers, but this should normally work:

ax[1].autoscale_view('tight')

An alternative would be to manually set the xlim and ylim of the axes:

ax[1].set_xlim(0,image_labels.shape[1])
ax[1].set_ylim(0,image_labels.shape[0])
Rutger Kassies
  • 61,630
  • 17
  • 112
  • 97