matplotlib draw line between subplots

Solutions on MaxInterview for matplotlib draw line between subplots by the best coders in the world

showing results for - "matplotlib draw line between subplots"
Alice
02 Sep 2019
1import matplotlib.pyplot as plt
2from matplotlib.patches import ConnectionPatch
3import numpy as np
4
5fig = plt.figure(figsize=(10,5))
6ax1 = fig.add_subplot(121)
7ax2 = fig.add_subplot(122)
8
9x,y = np.random.rand(100),np.random.rand(100)
10
11ax1.plot(x,y,'ko')
12ax2.plot(x,y,'ko')
13
14i = 10
15xy = (x[i],y[i])
16con = ConnectionPatch(xyA=xy, xyB=xy, coordsA="data", coordsB="data",
17                      axesA=ax2, axesB=ax1, color="red")
18ax2.add_artist(con)
19
20ax1.plot(x[i],y[i],'ro',markersize=10)
21ax2.plot(x[i],y[i],'ro',markersize=10)
22
23
24plt.show()
25
similar questions
queries leading to this page
matplotlib draw line between subplots