Numpy matlibplot基于矩阵绘制线

Numpy matlibplot基于矩阵绘制线,numpy,matplotlib,Numpy,Matplotlib,matplotlib和numpy都是新的 我有一个代表L形的矩阵: import numpy as np L = np.array([[1, 1, 1.5, 1.5, 2, 2], [2, 4, 4, 2.5, 2.5, 2]]) 如何在matplotlib中绘制此图?让我们尝试一下高级索引: plt.plot(*L[:, range(-1,L.shape[1])]) plt.xlim(0, 5) plt.ylim(0, 5) plt.show() 或者更自然地使用Patch.Polygo

matplotlib和numpy都是新的

我有一个代表L形的矩阵:

import numpy as np
L = np.array([[1, 1, 1.5, 1.5, 2, 2], [2, 4, 4, 2.5, 2.5, 2]])


如何在matplotlib中绘制此图?

让我们尝试一下高级索引:

plt.plot(*L[:, range(-1,L.shape[1])])
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.show()
或者更自然地使用
Patch.Polygon

from matplotlib.patches import Polygon

fig, ax = plt.subplots()
ax.add_patch(Polygon(L.T, facecolor='None', edgecolor='C0'))
ax.set_xlim(0,5)
ax.set_ylim(0,5)
plt.show()
输出:


让我们尝试一下高级索引:

plt.plot(*L[:, range(-1,L.shape[1])])
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.show()
或者更自然地使用
Patch.Polygon

from matplotlib.patches import Polygon

fig, ax = plt.subplots()
ax.add_patch(Polygon(L.T, facecolor='None', edgecolor='C0'))
ax.set_xlim(0,5)
ax.set_ylim(0,5)
plt.show()
输出: