简体   繁体   English

如何在matplotlib中绘制一条轴外的线(图中坐标)?

[英]How to draw a line outside of an axis in matplotlib (in figure coordinates)?

Matplotlib has a function that writes text in figure coordinates (.figtext()) Matplotlib有一个函数,用于在图形坐标中写入文本(.figtext())

Is there a way to do the same but for drawing lines? 有没有办法做同样的但绘制线条?

In particular my goal is to draw lines to group some ticks on the y-axis together. 特别是我的目标是画线以将y轴上的一些刻度组合在一起。

This will do it: 这样做:

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()

But if you want to align with ticks, then why not use plot coordinates? 但是如果你想与刻度线对齐,那么为什么不使用绘图坐标呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM