Python中的 matplotlib.pyplot.plot_date()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。
matplotlib.pyplot.plot_date()函数:
matplotlib 库的 pyplot 模块中的plot_date()函数用于绘制包含日期的数据。
Syntax:
Parameters: This method accept the following parameters that are described below:
- x, y: These parameter are the horizontal and vertical coordinates of the data points.
- fmt: This parameter is an optional parameter and it contains the string value.
- tz: This parameter is the time zone to use in labeling dates.It contain timezone string.
- xdate: This parameter is also an optional parameter. And it contain boolean values with default value True. If True, the x-axis will be interpreted as Matplotlib dates.
- ydate: This parameter is also an optional parameter. And it contain boolean values with default value True. If True, the y-axis will be interpreted as Matplotlib dates.
Returns: This returns the following:
- lines:This returns the list of Line2D objects representing the plotted data.
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.plot_date()函数:
示例 #1:
matplotlib.pyplot.plot_date(x, y, fmt='o', tz=None, xdate=True, ydate=False, hold=None, data=None, **kwargs)
输出:
示例 #2:
# Implementation of matplotlib function
import datetime
import matplotlib.pyplot as plt
from matplotlib.dates import drange
import numpy as np
date1 = datetime.datetime(2020, 4, 2)
date2 = datetime.datetime(2020, 4, 12)
delta = datetime.timedelta(hours = 24)
dates = drange(date1, date2, delta)
y = np.arange(len(dates))
plt.plot_date(dates, y ** 2)
plt.title('matplotlib.pyplot.plot_date() function Example', fontweight ="bold")
plt.show()
输出: