Networkx는 Matplotlib을 사용합니다.PNG에서 stdout/http 응답으로 networkx 그래프 그리기
직접하기 matplotlib, 이미지가 매우 간단 역할을하는 서버 스크립트와(단순에 대한 병 사용) : 그러나
import matplotlib.pyplot as plot
from matplotlib.backend.backends_agg import FigureCanvasAgg
from matplotlib.figure import Figure
from StringIO import StringIO
from bottle import route, response
@route("/plot.png")
def serve_image():
F = Figure() # new figure
P = F.add_subplot(111) # new plot container inside the figure
P.plot(list(range(10)), list(range(10))) # simple plot
PNG = StringIO() # container for PNG data
canvas = FigureCanvasAgg(F) # create image
canvas.print_png(PNG) # draw image into the container
response.content_type = "image/png" # duh
return PNG.getvalue() # return contents of the container
을 Networkx 암시하기 matplotlib , 그림 또는 인스턴스를 생성, 사용하지 않을 것 subplots. 매뉴얼은 일반적으로 다음과 같습니다.
networkx.draw(my_graph)
plot.show()
이 플롯을 PNG 이미지로 제공하는 방법은 무엇입니까?
와우, 잘못된 이름에 대해 이야기 해주세요! 나는 matplotlib을 해킹 - 할 - 할 - 일종의 방법으로 사용하고 결코 체계적으로 배울 수 없다 - 그래서 나는 결코 "축"이 "음모"를 의미하지는 않을 것이라고 생각한다. 감사! –
글쎄요, 명확히하기 위해,'axis'는 matplotlib 용어에서'axes'와 다릅니다. 'Axes' 인스턴스 (일반적으로'ax'라고 함)는 "플롯"이며, "xaxis"와 "yaxis"는 모두'Axis'의 인스턴스입니다. 상관없이 그것을 도왔 으면 좋겠다! –