python - 如何正确绘制自然对数?
问题描述
我不小心弄乱了我的代码,我无法重新创建它。
我认为最大的问题是每当我(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()
解决方案
您的函数4*np.log(2*x+3)-1
在 x = -3/2 处具有渐近线。你为什么不试试
x = np.arange(-3/2 + 0.01, 10, 0.1)
反而?
推荐阅读
- salesforce - Google Dialogflow 和 Salesforce 之间的集成?
- python - 有没有办法将值传递给其他 python 脚本调用的 python 脚本的输入提示?
- java - 如何在 Junit 中测试 logstash Marker
- npm - PhantomJS 不运行 .create()
- angular9 - 如何获取指令以对组件中的 EventEmitter 做出反应
- vue.js - 如何将 Vue 3 与 Vuetify 连接起来?
- javascript - 在下一个数组中查找要替换的对象数组
- r - Catboost 预测概率为负
- laravel - 如何在 laravel 中集成 paypal
- flutter - SingleChildScrollView 在对话框中不起作用