Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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
使用networkx和Python在MPLS传单上打印问题_Python_Networkx_Sna - Fatal编程技术网

使用networkx和Python在MPLS传单上打印问题

使用networkx和Python在MPLS传单上打印问题,python,networkx,sna,Python,Networkx,Sna,我正在研究一个社会网络分析问题,我有一个有向图。以前,我在将边导入图形文件时遇到了一个问题,但问题已经解决。然而,我在尝试在地图上绘制图形时遇到了另一个问题,而之前在无向图上绘制图形时,它是有效的。我得到了这个错误“ValueError:Unrecognized code:S”,下面是我所有的脚本: import mplleaflet import matplotlib.pyplot as plt import networkx as nx import numpy as np import p

我正在研究一个社会网络分析问题,我有一个有向图。以前,我在将边导入图形文件时遇到了一个问题,但问题已经解决。然而,我在尝试在地图上绘制图形时遇到了另一个问题,而之前在无向图上绘制图形时,它是有效的。我得到了这个错误“ValueError:Unrecognized code:S”,下面是我所有的脚本:

import mplleaflet
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
import pandas as pd
导入边缘和节点数据帧 设置有向图 输出:真

以前它是无方向的,在地图上绘制一切都是可能的。现在我把它定向了,在地图上绘图就不再有效了,我也不知道为什么

设置坐标 绘制地图
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在里面
1图,ax=plt.子批次(图尺寸=(20,13))
2nx.绘图(G,位置=坐标)
---->3.传单显示(图=图)
~/anaconda3/lib/python3.7/site-packages/mplplaople//\u display.py在显示中(图,closefig,**kwargs)
151 plt.关闭(图)
152
-->153 html=图到图html(图,**kwargs)
154
155#我们将所有内容都嵌入到iframe中。
~/anaconda3/lib/python3.7/site-packages/mplplaople//u display.py在图到图html中(图、模板、平铺、crs、epsg、嵌入链接)
82渲染器=渲染器(crs=crs,epsg=epsg)
83导出器=导出器(渲染器)
--->84.运行(图)
85
86属性=_属性+“|”+瓷砖[1]
运行中的~/anaconda3/lib/python3.7/site-packages/mplplaople/mplexporter/exporter.py(self,图)
49导入matplotlib.pyplot作为plt
50 plt.关闭(图)
--->51.自爬网图(图)
52
53@staticmethod
爬行图中的~/anaconda3/lib/python3.7/site-packages/mplplaople/mplexporter/exporter.py(self,图)
116 props=utils.get_figure_properties(图)):
117对于图轴中的ax:
-->118自动爬网(ax)
119
120 def爬网_ax(自身,ax):
爬网ax中的~/anaconda3/lib/python3.7/site-packages/mplplaople/mplexporter/exporter.py(self,ax)
136自我绘制文本(斧头,艺术家)
137对于ax.patches中的修补程序:
-->138自行绘制补片(斧头,补片)
139对于ax.collections中的集合:
140自绘制集合(ax,集合)
绘图补丁中的~/anaconda3/lib/python3.7/site-packages/mplplaople/mplexporter/exporter.py(self、ax、patch、force\u trans)
225路径代码=路径代码,
226样式=线条样式,
-->227 mplobj=补丁)
228
229 def draw_集合(自身、ax、集合、,
绘图路径中的~/anaconda3/lib/python3.7/site-packages/mplploaple/plople\u renderer.py(self、数据、坐标、路径码、样式、偏移、偏移坐标、mplobj)
123其他:
124数据=[c.tolist()表示数据中的c]
-->125环=列表(iter_环(数据、路径码))
126
127如果样式['facecolor']!='none':
iter环中的~/anaconda3/lib/python3.7/site-packages/mplplaople/utils.py(数据、路径码)
12环。附加(点)
13其他:
--->14 raise VALUERROR('无法识别的代码:{}'。格式(代码))
15
16如果透镜(环):
ValueError:无法识别的代码:S
非常感谢你! 边缘csv文件

节点文件


这似乎是一个已知的错误:我会让软件包的作者知道它也会影响到您。他们可能会给它分配更高的优先级。实际上,这可能已经被修复(尽管问题仍然存在)。请参阅源代码。安装一个更新的版本(可能来自源代码),可能会修复您的问题。
edges = pd.read_csv("./edges.csv", sep = ";")
nodes = pd.read_csv("./nodes_coordinates.csv", sep = ";")
G = nx.DiGraph()
G = nx.from_pandas_edgelist(edges, source = "from",
                                   target = "to",
                                   create_using = nx.DiGraph)
data = nodes.set_index("node").to_dict("index").items()
G.add_nodes_from(data)
nx.is_directed(G)
coordinates_dict = {}
for node in nodes.node:
    coordinates_dict[node] = list(nodes.loc[nodes.node == node ,['lon','lat']].values[0])
fig, ax = plt.subplots(figsize =(20,13))
nx.draw(G, pos = coordinates_dict)
mplleaflet.display(fig = fig)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-43-33a2a6f2d48a> in <module>
      1 fig, ax = plt.subplots(figsize =(20,13))
      2 nx.draw(G, pos=coordinates_dict)
----> 3 mplleaflet.display(fig=fig)

~/anaconda3/lib/python3.7/site-packages/mplleaflet/_display.py in display(fig, closefig, **kwargs)
    151         plt.close(fig)
    152 
--> 153     html = fig_to_html(fig, **kwargs)
    154 
    155     # We embed everything in an iframe.

~/anaconda3/lib/python3.7/site-packages/mplleaflet/_display.py in fig_to_html(fig, template, tiles, crs, epsg, embed_links)
     82     renderer = LeafletRenderer(crs=crs, epsg=epsg)
     83     exporter = Exporter(renderer)
---> 84     exporter.run(fig)
     85 
     86     attribution = _attribution + ' | ' + tiles[1]

~/anaconda3/lib/python3.7/site-packages/mplleaflet/mplexporter/exporter.py in run(self, fig)
     49             import matplotlib.pyplot as plt
     50             plt.close(fig)
---> 51         self.crawl_fig(fig)
     52 
     53     @staticmethod

~/anaconda3/lib/python3.7/site-packages/mplleaflet/mplexporter/exporter.py in crawl_fig(self, fig)
    116                                        props=utils.get_figure_properties(fig)):
    117             for ax in fig.axes:
--> 118                 self.crawl_ax(ax)
    119 
    120     def crawl_ax(self, ax):

~/anaconda3/lib/python3.7/site-packages/mplleaflet/mplexporter/exporter.py in crawl_ax(self, ax)
    136                     self.draw_text(ax, artist)
    137             for patch in ax.patches:
--> 138                 self.draw_patch(ax, patch)
    139             for collection in ax.collections:
    140                 self.draw_collection(ax, collection)

~/anaconda3/lib/python3.7/site-packages/mplleaflet/mplexporter/exporter.py in draw_patch(self, ax, patch, force_trans)
    225                                 pathcodes=pathcodes,
    226                                 style=linestyle,
--> 227                                 mplobj=patch)
    228 
    229     def draw_collection(self, ax, collection,

~/anaconda3/lib/python3.7/site-packages/mplleaflet/leaflet_renderer.py in draw_path(self, data, coordinates, pathcodes, style, offset, offset_coordinates, mplobj)
    123             else:
    124                 data = [c.tolist() for c in data]
--> 125             rings = list(iter_rings(data, pathcodes))
    126 
    127             if style['facecolor'] != 'none':

~/anaconda3/lib/python3.7/site-packages/mplleaflet/utils.py in iter_rings(data, pathcodes)
     12             ring.append(point)
     13         else:
---> 14             raise ValueError('Unrecognized code: {}'.format(code))
     15 
     16     if len(ring):

ValueError: Unrecognized code: S