Python中的 Matplotlib.pyplot.show()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。
示例代码 –
# sample code
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [16, 4, 1, 8])
plt.show()
输出:
matplotlib.pyplot.show()函数
matplotlib 库的 pyplot 模块中的show()函数用于显示所有图形。
Syntax:
Parameters: This method accepts only one parameter which is discussed below:
- block : This parameter is used to override the blocking behavior described above.
Returns: This method does not return any value.
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.show()函数:
示例 #1:
matplotlib.pyplot.show(*args, **kw)
输出:
示例 #2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.arange(20) / 50
y = (x + 0.1)*2
val1 = [True, False] * 10
val2 = [False, True] * 10
plt.errorbar(x, y,
xerr = 0.1,
xlolims = True,
label ='Line 1')
y = (x + 0.3)*3
plt.errorbar(x + 0.6, y,
xerr = 0.1,
xuplims = val1,
xlolims = val2,
label ='Line 2')
y = (x + 0.6)*4
plt.errorbar(x + 1.2, y,
xerr = 0.1,
xuplims = True,
label ='Line 3')
plt.legend()
fig.suptitle('matplotlib.pyplot.show() Example')
plt.show()
输出: