【发布时间】:2020-07-23 14:54:03
【问题描述】:
创建多个绘图的 Python 方法是什么?
我在下面编写了一些带有绘图变量的代码。我的直觉是编写一组对象进行迭代。看起来 Python 中的对象比我习惯的那种 Javascript/JSON 对象要复杂一些。
关于“Python 方式”的任何提示来完成我需要在这里完成的事情?
import pandas as pd
import networkx as nx
from networkx.algorithms
import community
import matplotlib.pyplot as plt
from datetime import datetime
graph = pd.read_csv('C:/Users/MYDIR/MYSOURCE.csv')
filename_prefix = datetime.now().strftime("%Y%m%d-%H%M%S")
#begin stuff that changes every plot
filename_suffix = 'suffix_one'
directory = 'C:/Users/MYDIR/';
title='MY_TITLE'
axis1='AXIS1';
axis2='AXIS2';
color = 'lightgreen';
#end stuff that changes every plot
df = graph[[axis1,axis2]]
G = nx.from_pandas_edgelist(df, axis1, axis2 );
plt.figure(figsize=(10,5))
ax = plt.gca()
ax.set_title(title)
nx.draw(G,with_labels=True, node_color=color, ax=ax)
_ = ax.axis('off')
#plt.show()
plt.savefig(directory + filename_prefix +'_' + title);
#plt.savefig(filename_prefix +'_' + filename_suffix + '.png')
【问题讨论】:
-
多个子图到底是什么?在此示例中,您似乎只有一个图表。虽然这是一般情况的示例stackoverflow.com/questions/61040515/…
标签: python matplotlib networkx