この質問の助けをいただければ幸いです。
matplotlib を使用して次のコードを作成し、同じ軸上にグラフといくつかの円をプロットしました。
import sys,os,re
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
from matplotlib.patches import Ellipse, Circle
class GraphForPlot:
def __init__(self):
self.G = nx.Graph()
self.Components = []
self.ActiveStatus = {}
self.Nodes = []
self.Position = {}
self.Color = []
self.p = {}
そして、メイン関数には次のものがあります
fig, PlotAxes = plt.subplots(nrows=1, ncols=2)
plt.tight_layout()
for i in range(0, len(GPlot)):
PlotAxes[i].xaxis.set_major_formatter(mtick.NullFormatter())
PlotAxes[i].yaxis.set_major_formatter(mtick.NullFormatter())
PlotAxes[i].axis([-25,1025,-25,1025])
for j in GPlot[i].G.nodes():
PlotAxes[i].add_artist(Circle((GPlot[i].Position[j][0],GPlot[i].Position[j][1]), GPlot[i].p[j], color='y'))
nx.drawing.nx_pylab.draw_networkx_nodes(GPlot[i].G, GPlot[i].Position, node_size=10, node_color=GPlot[i].Color, ax=plt.subplot(1,2,i+1))
if (GPlot[i].G.edges != []): nx.drawing.nx_pylab.draw_networkx_edges(GPlot[i].G, GPlot[i].Position, edge_color = 'black', ax=plt.subplot(1,2,i+1))
PlotAxes[i].set_aspect(1)
私が欲しいもの:円が下に来て、グラフが上に来るようにしたい. (円レイヤーの上のエッジ)。
私が得たもの:図の端が見えません。私の推測では、それは円の下に存在します。
サンプル データ インスタンス。
ここにデータがあります
GPlot[0].Components = [[0],[1],[2],[4],[3,5]]
GPlot[0].ActiveStatus = {(0,): 0, (1,): 1, (2,): 0, (4,): 1, (3, 5): 1}
GPlot[0].p = {0: 0.0, 1: 179.5, 2: 0.0, 3: 179.5, 4: 179.5, 5: 179.5}
GPlot[0].Position = {0: [918.476975980191, 566.175809107923], 1: [712.224117254128, 320.20223881946], 3: [136.674359018882, 835.172432802382], 4: [115.261650368544, 74.1499048601371], 5: [1.41743386570314, 502.881853371971]}
GPlot[0].Color = ['black', 'red', 'white', 'white', 'white']
GPlot[1].Components = [[0],[1],[2],[3],[4],[5]]
GPlot[1].ActiveStatus = {(0,): 0, (1,): 0, (2,): 1, (3,): 1, (4,): 1, (5,): 1}
GPlot[1].p = {0: 0.0, 1: 0.0, 2: 179.5, 3: 179.5, 4: 179.5, 5: 179.5}
GPlot[1].Position = {0: [689.232465921313, 844.969550926396], 2: [942.858050963379, 484.834574765457], 3: [136.674359018882, 835.172432802382], 4: [115.261650368544, 74.1499048601371], 5: [1.41743386570314, 502.881853371971]}
GPlot[1].Color = ['black', 'red', 'white', 'white', 'white']
グラフについては、次のようにします。
H = nx.path_graph(6)
GPlot[0].G.add_nodes_from(H)
GPlot[0].G.add_edge(3,5)
GPlot[1].G.add_nodes_from(H)
これで十分だと思います。