垂直线不遵守最小,最大限制(matplotlib)

时间:2013-06-05 18:21:55

标签: python matplotlib

问题的最小工作示例:

import matplotlib.pyplot as plt

horiz_line = 0.0005
vert_line = 110
x_data = [10, 30, 50, 70, 90, 110, 130, 150, 170, 190, 210, 230, 250, 270, 290, 310, 330, 350, 370, 390, 410, 430, 450, 470, 490]
y_data = [0.0074999999999999997, 0.011875, 0.0057812499999999999, 0.0036458333333333334, 0.0020312500000000001, 0.0013125000000000001, 0.00098958333333333342, 0.00089285714285714283, 0.00074218750000000001, 0.00093749999999999997, 0.00071874999999999999, 0.00088068181818181821, 0.00078125000000000004, 0.0004807692307692308, 0.00055803571428571425, 0.00083333333333333339, 0.00066406250000000005, 0.00069852941176470592, 0.00059027777777777778, 0.00059210526315789478, 0.00062500000000000001, 0.0007291666666666667, 0.00068181818181818187, 0.00059782608695652171, 0.00053385416666666663]

fig = plt.figure() # create the top-level container

# horizontal line
plt.axhline(y=horiz_line, xmin=0, xmax=max(x_data), color='red', zorder=1)

# vertical line
plt.axvline(x=vert_line, ymin=0, ymax=max(y_data), color='red', zorder=2)

plt.scatter(x_data, y_data, s=150, color='blue', zorder=3)

plt.show()

这给了我这个:

enter image description here

注意x=110处的红色小垂线。为什么不尊重min&我使用ymin=0, ymax=max(y_data)设置的最高限额(应为min=0; max=0.011875)?

1 个答案:

答案 0 :(得分:21)

您似乎想要hlinesvlines而不是axhlineaxvline提供的功能,因为后两者使用Axes coordinate system,而{ {1}}和hlines使用data coordinate system

所以你的代码应该是

vlines

enter image description here