Python 如何在matplotlib(地物坐标)中的轴外绘制线?
Matplotlib有一个函数,用于在地物坐标(.figtext())中写入文本 除了画线之外,有没有其他方法可以做到这一点 特别是,我的目标是绘制线条,将y轴上的一些记号组合在一起。这样做:Python 如何在matplotlib(地物坐标)中的轴外绘制线?,python,matplotlib,plot,Python,Matplotlib,Plot,Matplotlib有一个函数,用于在地物坐标(.figtext())中写入文本 除了画线之外,有没有其他方法可以做到这一点 特别是,我的目标是绘制线条,将y轴上的一些记号组合在一起。这样做: from matplotlib import pyplot, lines import numpy x = numpy.linspace(0,10,100) y = numpy.sin(x)*(1+x) fig = pyplot.figure() ax = pyplot.subplot(111) ax
from matplotlib import pyplot, lines
import numpy
x = numpy.linspace(0,10,100)
y = numpy.sin(x)*(1+x)
fig = pyplot.figure()
ax = pyplot.subplot(111)
ax.plot(x,y,label='a')
# new clear axis overlay with 0-1 limits
ax2 = pyplot.axes([0,0,1,1], axisbg=(1,1,1,0))
x,y = numpy.array([[0.05, 0.1, 0.9], [0.05, 0.5, 0.9]])
line = lines.Line2D(x, y, lw=5., color='r', alpha=0.4)
ax2.add_line(line)
pyplot.show()
但是,如果您想与记号对齐,那么为什么不使用打印坐标?这会更好,但我无法让它在轴之外绘制。我想画记号标签的位置。(在绘图位置之外)(我尝试了基本上是
ax的方法。在上面的示例中添加线(line)
,但坐标大致位于刻度的位置…@Max在这种情况下,只需设置line。设置剪辑(False)
。你想要另一个答案来证明这一点吗?谢谢。设置剪辑(错误)是一个很好的提示。我通过在图形坐标中计算线的位置来解决我的问题,但现在我知道了未来的情况。无需再写一个答案——再次感谢。@Paul的评论本身可能就是一个答案。请注意,axisbg
不赞成使用facecolor
。