gpt4 book ai didi

python - 将轴线添加到 matplotlib 图中

转载 作者:行者123 更新时间:2023-11-30 22:04:43 25 4
gpt4 key购买 nike

我正在使用“ipython jupyter笔记本”。我的问题是:

如何将轴线添加到图中,即。 y=0 和 x=0:

%matplotlib inline
from numpy import *
from matplotlib.pyplot import *
nil=seterr(divide='ignore', invalid='ignore')

t = arange(-2, 2, 0.1)
y1 = exp(t)
y2 = exp(-t)

subplot(121)
title('y=exp(t)')
ylabel('y')
xlabel('t')
grid()
plot(t, y1, '-')

subplot(122)
title('y=exp(-t)')
ylabel('y')
xlabel('t')
grid()
plot(t, y2, '-')
show()

enter image description here

最佳答案

实现这一点的最简单方法(不幸的是,没有花哨的箭头)是使用 axvline 和 axhline 在 x=0 和 y=0 处绘制线条,分别是:

t = arange(-2, 2, 0.1)
y2 = exp(-t)
axhline(0,color='red') # x = 0
axvline(0,color='red') # y = 0
grid()
plot(t, y2, '-')
show()

Example

关于python - 将轴线添加到 matplotlib 图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53200655/

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