【发布时间】:2016-04-26 16:49:36
【问题描述】:
我在网格上创建了一个包含多个子图的图。这些图在两个参数上有所不同,所以我希望它看起来像是在坐标系中排序的。
我设法使用 matplotlib.lines.Line2D() 直接在图上的子图旁边绘制线条。 但我更喜欢有一个箭头而不是一条线,以使其更清晰。 (我可以使用 fig.text() 添加具体的参数值。)
I'd like the blue lines to be arrows
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from itertools import product
fig = plt.figure()
plotGrid = mpl.gridspec.GridSpec(2, 2)
x = np.linspace(0,10,10000)
y = [j* np.sin(x + i) for i,j in product(range(2), range(1,3))]
for i in range(4):
ax = plt.Subplot(fig, plotGrid[i])
for sp in ax.spines.values():
sp.set_visible(False)
ax.plot(x,y[i], color = 'r')
ax.set_xticks([])
ax.set_yticks([])
fig.add_subplot(ax)
all_axes = fig.get_axes()
#I would like these lines to be arrows
blcorPosn = 0.08 #bottom corner position
l1 = mpl.lines.Line2D([blcorPosn,blcorPosn], [1, blcorPosn],
transform=fig.transFigure, fig)
l2 = mpl.lines.Line2D([blcorPosn, 1], [blcorPosn, blcorPosn],
transform=fig.transFigure, fig)
fig.lines.extend([l1, l2])
我不确定这是否是要走的路。但是我现在花了一天的时间,到目前为止,我看到的唯一绘制箭头的方法是将它们直接绘制在轴上,但据我所知,这对我来说不是一个选择。
这也是我在这里的第一篇文章,因此非常感谢有关如何提问的建议。 谢谢
【问题讨论】:
标签: python matplotlib plot