gpt4 book ai didi

python - 减少 matplotlib quiver 中的边框

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:02 25 4
gpt4 key购买 nike

我愿意使用以下代码绘制一个简单的向量场:

import numpy
import matplotlib.pyplot as plt

def plot_quiver(vx, vy, fp):
plt.figure()

x_steps, y_steps = vx.shape

x, y = numpy.meshgrid(numpy.linspace(0, x_steps, x_steps), numpy.linspace(0, y_steps, y_steps))
m = numpy.sqrt(numpy.power(vx, 2) + numpy.power(vy, 2))

fig = plt.quiver(x, y, vx, vy, m)
plt.axes().set_aspect('equal')

l, r, b, t = plt.axis()
dx, dy = r-l, t-b
plt.axis([l-0.1*dx, r+0.1*dx, b-0.1*dy, t+0.1*dy])

plt.savefig(fp, format='pdf', bbox_inches='tight')
plt.show()
plt.close()

我不明白的是为什么我的上边框和右边框更宽,以及如何调整它。

enter image description here

最佳答案

matplotlib 似乎在矢量场大小之后获得下一个整数。
这里r, t = 70, 70。为了确保您的问题不依赖于 matplotlib 的缩放,请使用
plt.axis([-0.1*x_steps, 1.1*x_steps, -0.1*y_steps, 1.1*y_steps])

关于python - 减少 matplotlib quiver 中的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40889347/

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