首页 > 解决方案 > 如何正确绘制自然对数?

问题描述

我不小心弄乱了我的代码,我无法重新创建它。

我认为最大的问题是每当我(4ln(2x+3)-1)在我的代码中实现我的函数时,图形都会停止并且不会像以前那样显示渐近线。如果无论如何有人可以提供帮助,我将不胜感激!

import matplotlib.pyplot as plt
import numpy as np
def function(x):
    return np.log(x)
x = np.arange(0.01,10,0.1)
y = 4*np.log(2*x+3)-1
plt.plot(x,y)
plt.grid()
plt.xlim(-5,10)
plt.ylim(-20,10)
plt.title('Graph of g(x)',fontsize=10)
plt.plot(x,y, color="blue",  linewidth=1, linestyle="-", 
              label="g(x)=4ln(2x+3)-1")
plt.legend(loc='upper left')
plt.xlabel('x',fontsize=8)
plt.ylabel('log',fontsize=8)
plt.savefig('Graph of g(x)', bbox_inches='tight')
plt.show()
plt.grid()
plt.close()

标签: pythonmatplotlib

解决方案


您的函数4*np.log(2*x+3)-1在 x = -3/2 处具有渐近线。你为什么不试试

x = np.arange(-3/2 + 0.01, 10, 0.1)

反而?


推荐阅读