Two functions generate two sets of solutions. On the left side, solution by one function are listed and the other set of solution is on right.
I want to reproduce this kind of representation. I don't know what kind of plot it is, or how to program it, or what technology to use (but am most familiar with matplotlib
). Please guide me.
CodePudding user response:
I am not sure how the data looks like, but here's a solution using networkx.
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
# random data
bi = np.random.uniform(-5, 5, size=(20,))
vi = np.random.uniform(-5, 5, size=(20,))
def make_biGraph(S1, S2):
# Create the Bipartite Graph using the solution sets
B = nx.Graph()
edgelist = [(s1, s2) for s1, s2 in zip(S1, S2)]
B.add_edges_from(edgelist)
return B
B = make_biGraph(bi, vi)
def draw_graph(B, S1, S2):
pos = {}
pos.update((node, (1, node)) for node in S1)
pos.update((node, (2, node)) for node in S2)
fig, ax = plt.subplots()
nx.draw_networkx(B, pos=pos,
node_size=20,
node_color='k',
with_labels=False,
ax=ax
)
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)
ax.set_yticks([-5, 0, 5])
ax.set_xticks([1, 2])
ax.set_xticklabels([r'$\delta W,BI$', r'$\delta W,VI$'])
plt.show()
draw_graph(B, bi, vi)
On a side note
This looks like a ladder plot, I couldn't find any python based solution.
Here's a solution using r
CodePudding user response:
The concentric circles as markers can be achieved with plt.scatter. You can then plot the lines individually.
a = np.random.uniform(-.5,.5,10)
b = np.random.uniform(-.5,.5,10)
plt.scatter([0]*len(a), a, s=100, c='k')
plt.scatter([0]*len(a), a, s=75, c='white')
plt.scatter([0]*len(a), a, s=35, c='k')
plt.scatter([1]*len(b), b, s=100, c='k')
plt.scatter([1]*len(b), b, s=75, c='white')
plt.scatter([1]*len(b), b, s=35, c='k')
for x1,y1 in zip(a,b):
plt.plot([0,1], [x1,y1], c='k')
plt.xlim(-.25,1.25)