gpt4 book ai didi

python - 切割轴的边界

转载 作者:太空宇宙 更新时间:2023-11-04 03:57:01 26 4
gpt4 key购买 nike

我确实画了一个图,我需要调用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()

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

enter image description here

最佳答案

如果我正确理解了这个问题,我相信这应该可以实现您想要的:

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

关于python - 切割轴的边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17771696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com