Matplotlib 中的箭袋图
本篇文章教你如何使用 Matplotlib 制作箭袋图。
使用 Matplotlib 创建箭袋图
我们需要为 matplotlib.pyplot.quiver
函数提供四个参数来制作图表。X、Y 轴和 X、Y 矢量方向。
x 坐标是坐标数组的第一项,第二项是 Y 坐标。下一个数组也是如此,它代表向量。
代码:
import matplotlib.pyplot as plt
coordinates = [0, 0]
vector = [1, 2]
plt.quiver(coordinates[0], coordinates[1], vector[0], vector[1])
输出:
我们还可以制作多个指向不同方向的箭头。请记住,所有数组都需要具有相同数量的项目或长度。
代码:
import matplotlib.pyplot as plt
from random import randrange
x = [x for x in range(10)]
y = [y for y in range(10)]
vec_x = [randrange(-2, 2) for x in range(10)]
vec_y = [randrange(-2, 2) for x in range(10)]
plt.quiver(x, y, vec_x, vec_y)
输出:
完整代码:
import matplotlib.pyplot as plt
from random import randrange
x = [x for x in range(10)]
y = [y for y in range(10)]
vec_x = [randrange(-2, 2) for x in range(10)]
vec_y = [randrange(-2, 2) for x in range(10)]
plt.quiver(x, y, vec_x, vec_y)
相关文章
Pandas DataFrame DataFrame.shift() 函数
发布时间:2024/04/24 浏览次数:133 分类:Python
-
DataFrame.shift() 函数是将 DataFrame 的索引按指定的周期数进行移位。
Python pandas.pivot_table() 函数
发布时间:2024/04/24 浏览次数:82 分类:Python
-
Python Pandas pivot_table()函数通过对数据进行汇总,避免了数据的重复。
Pandas read_csv()函数
发布时间:2024/04/24 浏览次数:254 分类:Python
-
Pandas read_csv()函数将指定的逗号分隔值(csv)文件读取到 DataFrame 中。
Pandas 多列合并
发布时间:2024/04/24 浏览次数:628 分类:Python
-
本教程介绍了如何在 Pandas 中使用 DataFrame.merge()方法合并两个 DataFrames。
Pandas loc vs iloc
发布时间:2024/04/24 浏览次数:837 分类:Python
-
本教程介绍了如何使用 Python 中的 loc 和 iloc 从 Pandas DataFrame 中过滤数据。
在 Python 中将 Pandas 系列的日期时间转换为字符串
发布时间:2024/04/24 浏览次数:894 分类:Python
-
了解如何在 Python 中将 Pandas 系列日期时间转换为字符串