Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。
matplotlib.axes.Axes.format_ydata()函数
matplotlib库的axiss模块中的Axes.format_ydata()函数用于返回格式为y-value的y。
用法:
Axes.format_ydata(self, y)
以下示例说明了matplotlib.axes中的matplotlib.axes.Axes.format_ydata()函数:
范例1:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook
years = mdates.YearLocator()
months = mdates.MonthLocator()
years_fmt = mdates.DateFormatter('% Y')
with cbook.get_sample_data('goog.npz') as datafile:
data = np.load(datafile)['price_data'].view(np.recarray)
fig, ax = plt.subplots()
ax.plot('date', 'adj_close', data = data[:300], color ="green")
ax.xaxis.set_major_locator(years)
ax.format_ydata = lambda x:'$% 1.2f' % x
ax.grid(True)
fig.autofmt_xdate()
fig.suptitle('matplotlib.axes.Axes.format_ydata() function\
Example', fontweight ="bold")
plt.show()
输出:
范例2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook
years = mdates.YearLocator()
months = mdates.MonthLocator()
years_fmt = mdates.DateFormatter('% Y')
with cbook.get_sample_data('goog.npz') as datafile:
data = np.load(datafile)['price_data']
fig, ax = plt.subplots()
ax.plot('date', 'adj_close', data = data, color ="k")
ax.yaxis.set_major_locator(years)
ax.yaxis.set_major_formatter(years_fmt)
ax.yaxis.set_minor_locator(months)
ax.format_ydata = mdates.DateFormatter('% Y')
ax.grid(True)
fig.suptitle('matplotlib.axes.Axes.format_ydata() function\
Example', fontweight ="bold")
plt.show()
输出:
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.axes.Axes.format_ydata() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。