Skip to content

Instantly share code, notes, and snippets.

@cvanelteren
Created May 29, 2024 09:45
Show Gist options
  • Save cvanelteren/84ba76dcf2aac8861c15c38e4c3da3a1 to your computer and use it in GitHub Desktop.
Save cvanelteren/84ba76dcf2aac8861c15c38e4c3da3a1 to your computer and use it in GitHub Desktop.
cross_figure annotation
import proplot as plt, cmasher as cmr, pandas as pd,\
numpy as np, os, sys, networkx as nx, warnings,\
re
from pathlib import Path
warnings.simplefilter("ignore")
g = nx.krackhardt_kite_graph()
pos = nx.kamada_kawai_layout(g)
x, y = np.random.randn(2, 100)
# force perspective, height ratios produces weird outputs
# here
layout = [[1,2,3],
[4, 4, 4],
[4, 4, 4]]
pos = nx.rescale_layout_dict(pos, 1) # force -1, 1
fig, ax = plt.subplots(layout, share = 0, hspace = 0)
np.random.seed(0)
props = dict(
connectionstyle="arc3,rad=-0.2",
linewidth=10,
width=1,
# color="lightgray",
)
ax[-1].scatter(x, y)
for axi in ax[:3]:
nx.draw(g, pos = pos, ax = axi, node_size = 128)
axi.axis("equal")
target = np.random.randint(0, len(x))
source = axi
to = ax[-1]
axi.annotate("test", xytext = (x[target], y[target]),
xy = [0, -1],
textcoords = to.transData,
xycoords = source.transData,
arrowprops = props,
zorder = 10,
annotation_clip = False,
)
ax[-1].set_facecolor("none")
ax.format()
fig.show()
@cvanelteren
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment