如何在matplotlib中绘制轴线外的线(以图形坐标表示)? [英] How to draw a line outside of an axis in matplotlib (in figure coordinates)?
本文介绍了如何在matplotlib中绘制轴线外的线(以图形坐标表示)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Matplotlib 有一个在图形坐标中写入文本的函数 (.figtext())
Matplotlib has a function that writes text in figure coordinates (.figtext())
除了画线之外,有没有办法做同样的事情?
Is there a way to do the same but for drawing lines?
特别是我的目标是绘制线条以将 y 轴上的一些刻度组合在一起.
In particular my goal is to draw lines to group some ticks on the y-axis together.
推荐答案
这样做:
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?
这篇关于如何在matplotlib中绘制轴线外的线(以图形坐标表示)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文