Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib-绘制直线_Python_Python 3.x_Pandas_Matplotlib_Annotations - Fatal编程技术网

Python matplotlib-绘制直线

Python matplotlib-绘制直线,python,python-3.x,pandas,matplotlib,annotations,Python,Python 3.x,Pandas,Matplotlib,Annotations,鉴于以下代码部分: fig, (ax1, ax2) = plt.subplots(2, 1) num = sto_list.gt(70).sum(1) plt.yticks(fontsize = 25) df2 = web.DataReader('fb', 'yahoo', start, end) ax = num.plot(figsize=(45,25), ax=ax2, color = 'Red') df2.plot(y = 'Close',

鉴于以下代码部分:

    fig, (ax1, ax2) = plt.subplots(2, 1)
    num = sto_list.gt(70).sum(1)
    plt.yticks(fontsize = 25)
    df2 = web.DataReader('fb', 'yahoo', start, end)
    ax = num.plot(figsize=(45,25), ax=ax2, color = 'Red')
    df2.plot(y = 'Close', figsize=(45,25), ax=ax1, color = 'Green')
    ax.grid()
    ax1.xaxis.label.set_visible(False)
    ax.xaxis.label.set_visible(False)
这将生成一个如下所示的图表:

底部的子图是根据num绘制的:

num
Out[70]: 
Date
2015-07-06    33
2015-07-07    20
2015-07-08     4
2015-07-09     8
2015-07-10     8
              ..
2020-06-29    14
2020-06-30    13
2020-07-01    18
2020-07-02    20
2020-07-03    28
Length: 1228, dtype: int64
我想做的是画一条直线,只要它小于10,用这个:

plt.axvline(x=num.lt(10), ax = ax2)

但是我不能画出这条线。这样做的最佳方式是什么?

问题是
num.lt
返回一个序列,而
axvline
需要一个标量

尝试循环并为每个索引值绘制一条线:

dates = num[num.lt(10)].index
for d in dates:
    ax2.axvline(d)       

谢谢你的帮助,我理解你的解决方案。但是,我得到了以下错误:
AttributeError:'Line2D'对象没有属性“ax”
没有
ax
我如何知道它应该打印在哪里?