📜  Python中的 matplotlib.pyplot.arrow()

📅  最后修改于: 2022-05-13 01:55:14.428000             🧑  作者: Mango

Python中的 matplotlib.pyplot.arrow()

Matplotlib是一个非常强大的绘图库,对使用Python和 NumPy 的人很有用。为了进行统计干扰,可视化我们的数据变得非常必要,而 Matplotlib 是非常有用的工具。它提供类似 MATLAB 的接口,唯一的区别是它使用Python并且是开源的。

matplotlib.pyplot.arrow()

此函数根据传递给它的坐标将箭头添加到图形中。

示例 #1

Python3
import matplotlib.pyplot as plt
 
 
# Initializing values
# of x and y
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
 
# Plotting the graph
plt.plot(x, y)
 
# Adding an arrow to graph starting
# from the base (2, 4) and with the
# length of 2 units from both x and y
# And setting the width of arrow for
# better visualization
plt.arrow(2, 4, 2, 2, width = 0.05)
 
# Showing the graph
plt.show()


Python3
import matplotlib.pyplot as plt
 
 
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
 
plt.plot(x, y)
 
# Increasing head_width of
# the arrow by setting
# head_width parameter
plt.arrow(2, 4, 2, 2,
          head_width = 0.2,
          width = 0.05)
 
plt.show()


Python3
import matplotlib.pyplot as plt
 
 
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
plt.plot(x, y)
 
# changing the edge color
# to green
plt.arrow(2, 4, 2, 2,
          head_width = 0.2,
          width = 0.05,
          ec ='green')
 
plt.show()


输出:

matplotlib.pyplot.arrow()

例子2#

Python3

import matplotlib.pyplot as plt
 
 
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
 
plt.plot(x, y)
 
# Increasing head_width of
# the arrow by setting
# head_width parameter
plt.arrow(2, 4, 2, 2,
          head_width = 0.2,
          width = 0.05)
 
plt.show()

输出:

matplotlib.pyplot.arrow()

示例#3

Python3

import matplotlib.pyplot as plt
 
 
x =[1, 2, 3, 4, 5]
y =[2, 4, 6, 8, 10]
plt.plot(x, y)
 
# changing the edge color
# to green
plt.arrow(2, 4, 2, 2,
          head_width = 0.2,
          width = 0.05,
          ec ='green')
 
plt.show()

输出:

matplotlib.pyplot.arrow()