I have a script that plots point correspondences between images:
JavaScript
x
30
30
1
import matplotlib.pyplot as plt
2
import numpy as np
3
from matplotlib.patches import ConnectionPatch, Rectangle
4
5
dpi = 100
6
fontsize = 8
7
offset = 0
8
img_size = (235, 190)
9
10
image_1 = np.zeros(img_size)
11
image_2 = np.zeros(img_size)
12
num_points = 50
13
points_x_1 = np.random.randint(190, size=(num_points,))
14
points_y_1 = np.random.randint(235, size=(num_points,))
15
points_x_2 = np.random.randint(190, size=(num_points,))
16
points_y_2 = np.random.randint(235, size=(num_points,))
17
18
fig, axes = plt.subplots(1, 2, figsize=(2 * img_size[1] / dpi, (img_size[0] + offset) / dpi), dpi=dpi)
19
axes[0].imshow(image_1)
20
axes[1].imshow(image_2)
21
colors = np.random.randint(256, size=(num_points, 3)) / 255.0
22
axes[0].scatter(points_x_1, points_y_1, s=20, c=colors)
23
axes[1].scatter(points_x_2, points_y_2, s=20, c=colors)
24
for i in range(num_points):
25
point_1 = (points_x_1[i], points_y_1[i])
26
point_2 = (points_x_2[i], points_y_2[i])
27
con = ConnectionPatch(xyB=point_1, xyA=point_2, coordsB="data", coordsA="data",
28
axesB=axes[0], axesA=axes[1], color=colors[i], linewidth=1)
29
axes[1].add_artist(con)
30
This results with an overlap of the axes ticks of one image with the other.
When I try to add fig.tight_layout()
at the end of the script the image’s size is drastically diminished:
Is it possible to keep the images large and avoid the ticks overlapping?
Thanks!
Advertisement
Answer
As mentioned by @JohanC, removing fig.tight_layout()
and replacing it with fig.subplots_adjust(wspace=0.3)
did the trick.