Python中的 Matplotlib.axis.Axis.set_tick_params()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.set_tick_params()函数
matplotlib 库的轴模块中的Axis.set_tick_params()函数用于设置刻度、刻度标签和网格线的外观参数。
Syntax: Axis.set_tick_params(self, axis=’major’, reset=False, \*\*kw)
Parameters: This method accepts the following parameters.
- axis: This parameter is the used to which axis to apply the parameters to.
Return value: This method does not returns any value.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.set_tick_params()函数:
示例 1:
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.02)
fig, ax1 = plt.subplots()
ax1.plot(t, np.sin(4*np.pi * t))
ax1.grid(True)
ax1.set_ylim((-2, 2))
ax1.xaxis.set_tick_params(labelcolor='r')
ax1.yaxis.set_tick_params(labelcolor='g')
plt.title('matplotlib.axis.Axis.set_tick_params()\n\
function Example', fontweight ="bold")
plt.show()
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.dates import (YEARLY, DateFormatter,
rrulewrapper, RRuleLocator, drange)
import numpy as np
import datetime
np.random.seed(19680801)
Val1 = rrulewrapper(YEARLY, byeaster=1, interval=5)
Val2 = RRuleLocator(Val1)
formatter = DateFormatter('%y/%m/%d')
date1 = datetime.date(2000, 1, 1)
date2 = datetime.date(2014, 4, 12)
delta = datetime.timedelta(days=10)
dates = drange(date1, date2, delta)
s = np.random.rand(len(dates))
fig, ax = plt.subplots()
plt.plot_date(dates, s,'go')
ax.xaxis.set_major_locator(Val2)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_tick_params(rotation=25,
labelsize=8 ,
labelcolor = "g")
ax.yaxis.set_tick_params(rotation=25,
labelsize=12 ,
labelcolor = "r")
plt.title('matplotlib.axis.Axis.set_tick_params()\n\
function Example', fontweight ="bold")
plt.show()
输出:
示例 2:
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.dates import (YEARLY, DateFormatter,
rrulewrapper, RRuleLocator, drange)
import numpy as np
import datetime
np.random.seed(19680801)
Val1 = rrulewrapper(YEARLY, byeaster=1, interval=5)
Val2 = RRuleLocator(Val1)
formatter = DateFormatter('%y/%m/%d')
date1 = datetime.date(2000, 1, 1)
date2 = datetime.date(2014, 4, 12)
delta = datetime.timedelta(days=10)
dates = drange(date1, date2, delta)
s = np.random.rand(len(dates))
fig, ax = plt.subplots()
plt.plot_date(dates, s,'go')
ax.xaxis.set_major_locator(Val2)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_tick_params(rotation=25,
labelsize=8 ,
labelcolor = "g")
ax.yaxis.set_tick_params(rotation=25,
labelsize=12 ,
labelcolor = "r")
plt.title('matplotlib.axis.Axis.set_tick_params()\n\
function Example', fontweight ="bold")
plt.show()
输出: