Matplotlib:如何针对两个轴镜像图像? [英] Matplotlib: How to mirror an image with respect to both axes?

查看:225
本文介绍了Matplotlib:如何针对两个轴镜像图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NetworkX 来评估网络中出现的动态。然后我直观地表示结果。我使用以下内容:

I am working with NetworkX in order to evaluate the dynamics that occur in a network. Then I visually represent the result. I work with the following:

#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)

我在视觉上得到的是一个不受欢迎的镜像。请参阅以下内容:

What I visually get is an UNWANTED MIRRORING. Please see below:

我的问题:有没有办法镜像输出图像水平和垂直,以便获得右边的图像,但是具有可读的标题和标签?

My question: is there a way of mirroring the output image both horizontally and vertically, so that the image to the right is obtained, but with readable titles and labels?

推荐答案

您只需要更改 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)

这篇关于Matplotlib:如何针对两个轴镜像图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆