兩個函式生成兩組解。在左側,列出了一個功能的解決方案,而另一組解決方案在右側。
我想重現這種表現形式。我不知道它是什么樣的情節,或者如何編程,或者使用什么技術(但我最熟悉matplotlib)。請指導我。

uj5u.com熱心網友回復:
我不確定資料的樣子,但這里有一個使用 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)

旁注
這看起來像一個梯形圖,我找不到任何基于 python 的解決方案。
這是使用 r的解決方案
uj5u.com熱心網友回復:
可以使用 plt.scatter 實作作為標記的同心圓。然后,您可以單獨繪制線條。
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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/387293.html
標籤:matplotlib 阴谋 图形
