我确实画了一个图,我需要调用axes (aspect = 'equal'),以保持坐标的比例。
但是,插入轴时,它也会插入边框,如 this figure (灰色区域为axes()插入的边框)。
我尝试设置 xlim() 和 ylim(),但这些命令仅作用于图形,而不作用于边框。
请帮助将轴边界设置为绝对 0,同时设置纵横比 equal。
编辑:
这是图表的图片——我只使用这段代码来设置图表。
(可以看到图形周围的白色边框):
ax = plt.gca()
ax.axis([0, 0, 1, 1])
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
[spine.set_visible(False) for spine in ax.spines.values()]
...NETWORKX CALLS...
xmax = max(points, key = lambda x : x[0])[0]
ymax = max(points, key = lambda x : x[1])[1]
xmin = min(points, key = lambda x : x[0])[0]
ymin = min(points, key = lambda x : x[1])[1]
xlim (xmin, xmax)
ylim (ymin, ymax)
show()
我希望最大限度地使用框架空间,并完全切割轴使用的边框。
请您参考如下方法:
如果我正确理解了这个问题,我相信这应该可以实现您想要的:
ax = plt.gca()
# Make axes occupy whole canvas
ax.set_position([0,0,1,1])
# Same scale on x- and y-axes, change x- and y-limits to keep
# axes ratio and position
# 'equal' gives same scaling on x- and y-axes
# 'datalim' changes the xlim and ylim to fit the axes inside its boundary
ax.set_aspect('equal', 'datalim')
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
[spine.set_visible(False) for spine in ax.spines.values()]
