Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib:如何镜像两个轴上的图像?_Python_Image_Matplotlib_Networkx_Mirroring - Fatal编程技术网

Python Matplotlib:如何镜像两个轴上的图像?

Python Matplotlib:如何镜像两个轴上的图像?,python,image,matplotlib,networkx,mirroring,Python,Image,Matplotlib,Networkx,Mirroring,我正在使用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 p

我正在使用
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)
#步骤1:创建原始网络
将networkx导入为nx
导入matplotlib.pyplotas plt
N=100
G=nx.grid_2d_图(N,N)#10000个节点的2d正则图
pos=dict((n,n)表示n个节点())#位置dict
labels=dict((i,j),i+(N-1-j)*N)表示G.nodes()中的i,j)
nx.relabel_节点(G,标签,False)
pos={y:x代表x,y在labels.iteritems()中}重命名的位置。位置(0,0)现在位于左上角。
H=G.copy()
#步骤2:动力学建模块
#步骤3:绘制生成的网络
G2=dict((k,v)表示状态中的k,v_nodes_model.items(),如果v<1)#必须从常规网格中删除的所有节点
H.从(G2)中删除节点
nx.draw\u networkx(H,pos=pos,带标签=False,节点大小=10)
plt.xlim(-20120,10)
plt.xticks(numpy.arange(-20130,20.0))
plt.ylim(-20120,10)
plt.yticks(努比阿兰奇(-20130,20.0))
plt.轴('on')
plt.绘图((0,100),(0,0),‘0.60’#第1行-故障阶段的视觉边界
plt.绘图((0,0),(0,100),‘0.60’#第2行-故障阶段的视觉边界
plt.图((01000),(100100),‘0.60’#第3行-故障阶段的视觉边界
plt.绘图((100100),(01000),‘0.60’#第4行-故障阶段的视觉边界
title_string=(“晶格网络,第2阶段”)
subtitle|string=('Impact&dynamics | Active nodes:'+str(act|u nodes|u model)+'+str(Failed|u nodes|haz+Failed|u nodes|model)+'+str总故障百分比:'+str numpy(约100*(Failed|nodes|haz+Failed|nodes|u|model)/10000,2))+'%
plt.suptitle(title_字符串,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)

我想你也得照镜子。在上面右边的例子中,你有x=0和y=0的点,而在左边的例子中你没有。我想镜像轴是很容易的。不要镜像轴这是一个不同的图表我想是的,我真正想做的是通过镜像轴来变换我的图像。这不是我想在生成错误图像(例如,使用Photoshop)后以图形方式更改的内容,而是在生成之前以数字方式更改的内容。您是否尝试过反转轴列表?您可以尝试生成从正值到负值的arange。通过这种方式,您将逆转AXE,在将问题发布到此处之前,您可能不清楚您为解决问题所做的努力。