转自:https://vimsky.com/examples/usage/matplotlib-pyplot-loglog-function-in-python.html
Matplotlib 是一个综合库,用于在 python 中创建交互式,静态和动画可视化。使用wxPython,SciPy,Tkinter 或 SciPy 之类的 general-purpose GUI 工具包,它提供了一个面向对象的 API,用于将图嵌入到应用程序中。 Matplotlib.pyplot 是使 Matplotlib 像 MATLAB 一样工作的函数集合。
在这里,我们将探索 Matplotlib.pyplot 的 loglog() 函数。它
用于在 x 和 y 轴上绘制对数刻度
。
用法:
loglog(X,Y)
其中,
X 和 Y 分别指 x 和 y 坐标。
使用的其他函数是 linespace()。它在指定的间隔内返回均等的数字。
用法:
np.linspace(start, stop, num, endpoint, retstep, dtype, axis)
其中,
Start
:您要显示线条的位置的序列起始值,或者我们可以说线条的起点Stop
:除非‘endpoint’设置为False,否则它是行停止处序列的结束值。Num
:要生成的样本数。必须为非负数。默认情况下为50。Endpoint
:与停止相同。如果为True,则stop是最后一个样本,否则stop将从序列中排除。Retstep
:如果为True,则返回(‘samples’, ‘step’),其中step
是样本之间的间隔。Dtype
:输出数组的类型。Axis
:结果中存储样本的轴,仅当开始或停止为array-like时才相关
例:没有 loglog()
# importing requried modules
import matplotlib.pyplot as plt
import numpy as np
# inputs to plot using loglog plot
x_input = np.linspace(0, 10, 50000)
y_input = x_input**8
# plotting the value of x_input and y_input using plot function
plt.plot(x_input, y_input)
输出:
例:与 loglog()
Python3
# importing requried modules
import matplotlib.pyplot as plt
import numpy as np
# inputs to plot using loglog plot
x_input = np.linspace(0, 10, 50000)
y_input = x_input**8
# plotting the value of x_input and y_input using loglog plot
plt.loglog(x_input, y_input)
输出: