Matplotlib.axes.axes.format_ydata() - 返回格式化为y值的y

Matplotlib.axes.axes.format_ydata()

Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Axes包含了大多数图形元素:Axis、Tick、Line2D、Text、Polygon等,并设置坐标系。Axes的实例通过callbacks属性支持回调。

函数:Matplotlib.axes.axes.format_ydata()

matplotlib库的Axes模块中的Axes.format_ydata()函数用于返回格式化为y值的y。

语法:

Axes.format_ydata(self, y)

下面的例子演示了matplotlib.axes.axes.format_ydata()函数在matplotlib.axes中的作用:

示例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()

输出:

Matplotlib.axes.axes.format_ydata()

示例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()

输出:

Matplotlib.axes.axes.format_ydata()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

matplotlib.axes