Matplotlib:如何相对于两个轴镜像图像?

Matplotlib: How to mirror an image with respect to both axes?

我正在与 NetworkX 合作,以评估网络中发生的动态。然后我直观地表示结果。我使用以下工具:

#Step 1: Creating the original network
import networkx as nx
import matplotlib.pyplotas plt
N=100
G=nx.grid_2d_graph(N,N) #2D regular graph of 10000 nodes
pos = dict( (n, n) for n in G.nodes() ) #Dict of positions
labels = dict( ((i, j), i + (N-1-j) * N ) for i, j in G.nodes() )
nx.relabel_nodes(G,labels,False)
pos = {y:x for x,y in labels.iteritems()} #Renamed positions. Position (0,0) is in the upper left corner now.
H=G.copy()

#Step 2: Dynamics modeling block

#Step 3: Plotting the resulting network
G2=dict((k, v) for k, v in status_nodes_model.items() if v < 1) #All nodes that must be removed from the regular grid
H.remove_nodes_from(G2)
nx.draw_networkx(H, pos=pos, with_labels=False, node_size = 10)
        plt.xlim(-20,120,10)
        plt.xticks(numpy.arange(-20, 130, 20.0))
        plt.ylim(-20,120,10) 
        plt.yticks(numpy.arange(-20, 130, 20.0))
        plt.axis('on')
        plt.plot((0, 100), (0, 0), '0.60') #Line1 - visual boundary for failure stages
        plt.plot((0, 0), (0, 100), '0.60') #Line2 - visual boundary for failure stages
        plt.plot((0, 100), (100, 100), '0.60') #Line3 - visual boundary for failure stages
        plt.plot((100, 100), (0, 100), '0.60') #Line4 - visual boundary for failure stages
        title_string=('Lattice Network, Stage 2') 
        subtitle_string=('Impact & dynamics | Active nodes: '+str(act_nodes_model)+' | Failed nodes: '+str(failed_nodes_haz+failed_nodes_model)+' | Total failure percentage: '+str(numpy.around(100*(failed_nodes_haz+failed_nodes_model)/10000,2))+'%')
        plt.suptitle(title_string, y=0.99, fontsize=17)
        plt.title(subtitle_string, fontsize=8)

我看到的是一个不需要的镜像。请看下面:

我的问题:有没有办法在水平和垂直方向镜像输出图像,这样右边的图像就是已获得,但具有可读的标题和标签?

您只需更改 pos 中的值。

my_pos = {}
for key in pos.keys():
     x,y = pos[key]
     my_pos[key] = (-x,-y)#or whatever function you want
nx.draw_networkx(H, pos=my_pos, with_labels=False, node_size = 10)