在xml文件中绘制图形

时间:2018-11-09 06:56:31

标签: matplotlib networkx

我想使用下面的python代码显示图形,但是出现图像上的语法错误。请帮助纠正此错误。我正在使用Python 3

import os
import sys
import fnss
import networkx as nx
import fnss
import cvxopt
import numpy as np
import codecs
import random
import matplotlib.pyplot as plt
topo_str = 'topo_peter.xml'
topology = fnss.read_topology(topo_str)
topology_directed = topology.to_directed(topology)
print nx.info(topology_directed)
nx.draw(topology_directed)
plt.show()

这就是我要得到的

File "<ipython-input-1-fa7157dd7268>", line 14
print nx.info(topology_directed)
      ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:0)

基于提供的信息:

14:42:30 Cloning into bare repository 'testing-repo.git'...
14:44:25 From bitbucket.org:TEST/testing-repo
14:44:25  * branch            HEAD       -> FETCH_HEAD
14:44:29 remote:
14:44:29  ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
14:44:29 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
14:44:29 hint: Updates were rejected because the remote contains work that you do
14:44:29 hint: not have locally. This is usually caused by another repository pushing
14:44:29 hint: to the same ref. You may want to first integrate the remote changes
14:44:29 hint: (e.g., 'git pull ...') before pushing again.
14:44:29 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
14:44:29 Everything up-to-date
14:44:29 Finished: SUCCESS

对于使用Python 3执行Python 2语句的人来说,这显然是一个简单的 lineChartOptions = { responsive: true, maintainAspectRatio: false, scales: { xAxes: [{ type: 'time', time: { parser: 'YYYY-MM-DD HH:mm:ss', unit: 'day', autoSkip: true, displayFormats: { day: 'MMM-DD' } }, ticks: { source: 'data', }, scaleLabel: { display: true, labelString: 'Date' } }], yAxes: [{ ticks: { beginAtZero:true, }, scaleLabel: { display: true, labelString: 'Values' } }] } } <canvas class ="can" baseChart [chartType]="lineChartType" [datasets]="lineChartData" [labels]="lineChartLabels" [options]="lineChartOptions" [colors]="lineChartColors" [legend]="true" (chartClick)="chartClicked($event)"> </canvas>

Python version: 3
Error message: invalid syntax on line 14 -> print nx.info(topology_directed)

对于Python 3,使用

syntax error

因此将print "something" # is valid for Python 2, but not Python 3 更改为print("something", "and more", "even more") 可解决问题。