Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。它是Python中令人惊叹的可视化库,用于数组的2D图,并用于与更广泛的SciPy堆栈配合使用。
Matplotlib.axis.Tick.update_from()函数
matplotlib库的轴模块中的Tick.update_from()函数用于将属性从其他属性复制到自身。
用法: Tick.update_from(self, other)
参数:此方法接受以下参数。
- other:此参数是要更新的属性。
返回值:此方法不返回任何值。
以下示例说明了matplotlib.axis中的matplotlib.axis.Tick.update_from()函数:
范例1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerLine2D
x = np.linspace(0, 4 * np.pi)
y1 = np.sin(x)
y2 = np.cos(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y1, c ='b', label ='y1', linewidth = 1.0)
ax.plot(x, y2, c ='g', label ='y2')
linewidth = 7
def update(prop1, prop2):
Tick.update_from(prop1, prop2)
prop1.set_linewidth(7)
plt.legend(handler_map ={plt.Line2D:HandlerLine2D(update_func = update)})
ax.set_title('matplotlib.axis.Tick.update_from() \
function Example', fontweight ="bold")
plt.show()
输出:
范例2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerLine2D
import matplotlib.transforms as mtransforms
fig, ax = plt.subplots()
l1, = ax.plot([0.1, 0.5, 0.9],
[0.1, 0.9, 0.5],
"go-")
l2, = ax.plot([0.1, 0.5, 0.9],
[0.5, 0.2, 0.7],
"yo-")
for l in [l1, l2]:
xx = l.get_xdata()
yy = l.get_ydata()
shadow, = ax.plot(xx, yy)
Tick.update_from(shadow, l)
ot = mtransforms.offset_copy(l.get_transform(),
ax.figure,
x = 4.0,
y =-6.0,
units ='points')
shadow.set_transform(ot)
ax.set_title('matplotlib.axis.Tick.update_from() \
function Example', fontweight ="bold")
plt.show()
输出:
注:本文由纯净天空筛选整理自 Matplotlib.axis.Tick.update_from() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。