Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Draw a line to connect points between subfigures

With matplotlib’s new subfigure – not subplot – but subfigure feature. I would like to draw a line between two subfigures. From my experimentation, I don’t believe connection patch (which works for subplots) works with this. Does anyone know if it possible?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can still use ConnectionPatch with subfigures.

Here is an example connecting (4, 8) on the first subfigure’s ax1a with (2, 5) on the second subfigure’s ax2:

import matplotlib.pyplot as plt
from matplotlib.patches import ConnectionPatch

fig = plt.figure()
sf1, sf2 = fig.subfigures(1, 2, wspace=0.07)

ax1a, ax1b = sf1.subplots(2, 1)
ax1a.scatter(4, 8)
ax1b.scatter(10, 15)

ax2 = sf2.subplots()
ax2.scatter(2, 5)

con = ConnectionPatch(
    xyA=(4, 8), coordsA='data', axesA=ax1a,
    xyB=(2, 5), coordsB='data', axesB=ax2,
    color='red',
)
ax2.add_artist(con)

plt.show()

figure result

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading