KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When I draw a figure using matplotlib how do I save it without extra margins? Usually when I save it as plt.savefig("figure.png") # or .pdf I get it with some margins: Example: import matplotlib.pyplot as plt import networkx as nx G=nx.Graph() G.add_edge('a','b',weight=1) G.add_edge('a','c',weight=1) G.add_edge('a','d',weight=1) G.add_edge('a','e',weight=1) G.add_edge('a','f',weight=1) G.add_edge('a','g',weight=1) pos=nx.spring_layout(G) nx.draw_networkx_nodes(G,pos,node_size=1200,node_shape='o',node_color='0.75') nx.draw_networkx_edges(G,pos, width=2,edge_color='b') plt.axis('off') plt.savefig("degree.png", bbox_inches="tight") plt.show() Update 2: The spaces are set inside the axes.. This is clear if I remove plt.axis('off') So I think there is some trick to use with the package Networkx.
Tags (comma-separated)
Save Edits
Cancel