python - 当 x 在 python 中介于 1 和 100 之间时,绘制 y=logx
问题描述
有人可以帮助如何绘制 y = log(x) 的图,x 在 Python 中介于 1 和 100 之间。我已经尝试了很多,但无法弄清楚如何做到这一点。
解决方案
您可以尝试使用 matplotlib 库。一个简单的散点图将来自以下代码:
import matplotlib.pyplot as plt
from math import log
x = range(1, 100)
y = [log(xi) for xi in x]
plt.scatter(x, y)
plt.show()
我还使用了数学库中的 log() 函数。如果您在 jupyter notebook 中编码,则不需要最后一行代码
plt.show()
您可以用“plt”结束单元格
import matplotlib.pyplot as plt
from math import log
x = range(1, 100)
y = [log(xi) for xi in x]
plt.scatter(x, y)
# some other operations in your code
# and you end with plt
plt
推荐阅读
- jasper-reports - 在 ReportServer 社区中创建报告和模板的最佳方式
- java - 程序在 IDE 中运行,但不是 .jar 文件
- c++ - 模板化 using 无法选择模板函数用作 Visual Studio 中的参数
- c# - 如何将 Class FooObject 转换为均实现接口 IObject 的类 BarObject?
- c++ - 类对象指针向量:如何在指针地址获取值?C++ 和 SDL_Rect
- javascript - JS 的 getTime() 是否适用于非 UTC 时区用户?
- java - 语句无法执行,请重试:oracle.kv.FaultException: no such object in table (12.1.4.3.11) (18.3.10)
- appium - 在ciscos anyconnect中无法点击appium
- regex - 在一个 sed 中匹配正负模式
- vue.js - Recaptcha v3 动作作为参数