

我有一个绘制图形的简短代码:
plt.figure(figsize=(15,15),dpi=300)
ax = plt.subplot(111)
nd = nx.draw_networkx_nodes(G, pos, node_color=node_cols, linewidths=1, node_size=node_sizes)
nd.set_edgecolor('w') #<- set the edgecolor to red on the node markers
nx.draw_networkx_edges(G, pos, edge_color=edge_cols,width=edge_sizes)
nx.draw_networkx_labels(G, pos, labels, font_size=fs, font_weight='bold')
plt.tick_params(
axis='both', # changes apply to both axes
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off', # labels along the bottom edge are off
left='off',
labelleft='off')
#plt.show()
plt.savefig('foo.pdf')在我的苹果iPython笔记本上运行时,和在微软的pycharm上运行时,尺寸是不同的。有没有办法解决这个问题?如何在知情的情况下指定edge_sizes和node_sizes?谢谢!
发布于 2017-11-20 02:42:36
jupyter笔记本中matplotlib图形的默认图形大小和dpi不同于通常的脚本。
你可以通过
import matplotlib.pyplot as plt
print(plt.rcParams["figure.figsize"])
print(plt.rcParams["figure.dpi"])它应该为jupyter笔记本打印[6.0, 4.0] 72.0,为脚本打印[6.4, 4.8] 100.0。
为了设置这些参数,可以使用
plt.rcParams["figure.figsize"] = 6,4
plt.rcParams["figure.dpi"] = 100将它们设置为所有输出,或者
plt.figure(figsize=(6,4), dpi=100) 对于一个人来说。这样,您可以确保脚本和notebook的输出是相同的。
https://stackoverflow.com/questions/47379297
复制相似问题