如何使用Matplotlib在图的中间绘制轴 [英] How to draw an axis in the middle of the figure using Matplotlib

查看:76
本文介绍了如何使用Matplotlib在图的中间绘制轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一条平行于y轴且在x轴中间的静态垂直线.当图中的一个平移时,该行不应移动. 我的目标是使图中间的垂直线作为参考线.我将使用其他一些数字来表示数据,这些数据将取决于x轴中间的x值.

I would like to draw a static vertical line that is parallel to the y-axis and which is at the middle of the x-axis. This line should not move when one pan in the figure. My goal is to have this vertical line in the middle of the figure as a reference line. I will have some other figures which represent data that will depend on the x value which is at the middle of the x-axis.

推荐答案

该行端点的坐标在轴坐标中为(0.5,0)和(0.5,1):

The coordinates of the endpoints of that line are (0.5, 0) and (0.5, 1) in axis coordinates:

from matplotlib.lines import Line2D
from matplotlib import pyplot

f=pyplot.figure()
a=f.add_subplot(111)
a.plot([3,1,4,1,5,9,2], color='k') # so you have some content
a.add_line(Line2D([0.5, 0.5], [0, 1], transform=a.transAxes,
                  linewidth=2, color='b'))
pyplot.show()

这篇关于如何使用Matplotlib在图的中间绘制轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆