剪切轴的边界

时间:2013-07-21 11:10:20

标签: python matplotlib

我画了一张图,我需要调用axes (aspect = 'equal'),以保持坐标的比例。

但是,插入轴时,它也会插入边框,例如this figure(灰色区域是轴()插入的边框。)

我尝试设置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()

我希望最大限度地使用框架空间,并完全切割轴使用的边框。

enter image description here

1 个答案:

答案 0 :(得分:2)

如果我正确理解了这个问题,我相信这应该达到你想要的目的:

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()]