在matplotlib上的图形下方画圆圈

在matplotlib上的图形下方画圆圈,matplotlib,networkx,Matplotlib,Networkx,在此问题上的任何帮助都将不胜感激 我使用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):

在此问题上的任何帮助都将不胜感激

我使用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) 

我希望这足够了

我认为您需要更改
zorder
,正如您在本文中看到的那样


我不熟悉networkx软件包,因此我不知道如何指定用于创建图形图形的艺术家的zorder

能否提供一些初始化
GPlot
的示例数据?我想复制你的情节。谢谢@MillaWell有没有一种方法可以将文件发送给您是的,但是如果其他人意外地遇到这个问题,他们也可以复制您的代码,这可能会对他们有所帮助。那么,是否有可能添加一个小版本的数据,以显示问题?如果不是:gmail网站的millawelldevcom@MillaWell-添加数据是为了澄清,您尝试过:
nx.drawing.nx\u pylab.drawing\u networkx\u节点(GPlot[i].G,…,zorder=3)
?zorder没有作为一个选项记录,但我不确定它是否传递给底层对象。较大的zorder数字会导致对象更靠近前景。在创建圆时,是否可以尝试zorder=0<代码>绘图轴[i]。添加艺术家(圆(…,color='y',zorder=0))效果很好。我只为圆添加了zorder=0。只有这个有效,我尝试的其他组合无效。谢谢