Python中的 Matplotlib.pyplot.xscale()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。在 Pyplot 中可以使用各种图,包括线图、等高线图、直方图、散点图、3D 图等。
matplotlib.pyplot.xscale()函数
matplotlib 库的 pyplot 模块中的xscale()函数用于设置 x 轴刻度。
Syntax: matplotlib.pyplot.xscale(value, \*\*kwargs)
Parameters: This method accept the following parameters that are described below:
- value: This parameter is the axis scale type to apply.
- **kwargs: There are different keyword arguments which are accepted and its depend on the scale.
Returns: This method does not returns any value.
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.xscale()函数:
示例 1:
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import EngFormatter
val = np.random.RandomState(19680801)
xs = np.logspace(1, 9, 100)
ys = (0.8 + 4 * val.uniform(size = 100)) * np.log10(xs)**2
plt.xscale('log')
plt.plot(xs, ys)
plt.xlabel('Frequency')
plt.title('matplotlib.pyplot.xscale() \
function Example\n', fontweight ="bold")
plt.show()
Python3
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
fig, ax4 = plt.subplots()
x = 10.0**np.linspace(0.0, 2.0, 15)
y = x**2.0
plt.xscale("log", nonposx ='clip')
plt.yscale("log", nonposy ='clip')
plt.errorbar(x, y, xerr = 0.1 * x,
yerr = 2.0 + 1.75 * y,
color ="green")
plt.ylim(bottom = 0.1)
plt.title('matplotlib.pyplot.xscale() \
function Example\n', fontweight ="bold")
plt.show()
输出:
示例 2:
Python3
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
fig, ax4 = plt.subplots()
x = 10.0**np.linspace(0.0, 2.0, 15)
y = x**2.0
plt.xscale("log", nonposx ='clip')
plt.yscale("log", nonposy ='clip')
plt.errorbar(x, y, xerr = 0.1 * x,
yerr = 2.0 + 1.75 * y,
color ="green")
plt.ylim(bottom = 0.1)
plt.title('matplotlib.pyplot.xscale() \
function Example\n', fontweight ="bold")
plt.show()
输出: