Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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 如何将日期转换为图形?np.linspace_Python_Pandas_Numpy_Datetime_Streamlit - Fatal编程技术网

Python 如何将日期转换为图形?np.linspace

Python 如何将日期转换为图形?np.linspace,python,pandas,numpy,datetime,streamlit,Python,Pandas,Numpy,Datetime,Streamlit,我使用streamlight输入日期数据,以便在其上构建图形。第一次这样做。我得到这个错误 datetime.date”对象不能解释为整数 据我所知,日期需要以某种方式转换。但是不要扔石头,我不知道怎么扔) 我了解streamlit在这里受到间接影响。我真的很困惑。它不工作的原因是因为np.linspace正在寻找整数作为它的输入。它不是用来创建日期范围的 使用类似“来自熊猫”的东西来制作日期范围 >>pd.日期范围(开始日期为2018年1月1日,结束日期为2018年8月1日) 日期时间索引(

我使用streamlight输入日期数据,以便在其上构建图形。第一次这样做。我得到这个错误

datetime.date”对象不能解释为整数

据我所知,日期需要以某种方式转换。但是不要扔石头,我不知道怎么扔)


我了解streamlit在这里受到间接影响。我真的很困惑。

它不工作的原因是因为
np.linspace
正在寻找整数作为它的输入。它不是用来创建日期范围的

使用类似“来自熊猫”的东西来制作日期范围

>>pd.日期范围(开始日期为2018年1月1日,结束日期为2018年8月1日)
日期时间索引(['2018-01-01','2018-01-02','2018-01-03','2018-01-04',',
'2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08'],
dtype='datetime64[ns]',freq='D')

是的,我已经试过了,但是我有点困惑,你能告诉我更多吗?你上面提供的代码没有显示你想做什么,Streamlight在这里与试图创建图形相切。你想创建什么图表?Y轴数据来自哪里,您想按日期绘制数据?谢谢您的回答,我补充了这个问题。我就是搞不懂,“一切都不符合评论”,也不应该这样。评论仅针对简短的问题和答案,这些问题和答案会导致编辑问题以进行澄清。
def SIR(y, t, N, beta, gamma):
        S, I, R = y
        dSdt = -beta * S * I / N
        dIdt = beta * S * I / N - gamma * I
        dRdt = gamma * I
        return dSdt, dIdt, dRdt

  st.subheader("Date parameters")

    today = datetime.date.today()
    tomorrow = today + datetime.timedelta(days=1)
    one_day = tomorrow - datetime.timedelta(days=1)

    start = st.date_input('Start date')
    end = st.date_input('End date', tomorrow)
    last = st.date_input('Last date', one_day)

    if start < end:
        st.success('Start date: `%s`\n\nEnd date: `%s`\n\n' % (start, end))
    else:
        st.error('Error: End date must fall after start date.')

    if last < end:
        st.success('Last date: `%s`\n\nEnd date: `%s`\n\n' % (last, end))
    else:
        st.error('Error: End date must fall after last date.')

    t = np.linspace(start, last, end)

ret = odeint(SIR, y0, t, args=(N, beta, gamma))

    S, I, R = ret.T

    def plotsir(t, S, I, R):
        f, ax = plt.subplots(1, 1, figsize=(10, 4))
        ax.plot(t, S, 'b', alpha=0.7, linewidth=2, label='Susceptible')
        ax.plot(t, I, 'y', alpha=0.7, linewidth=2, label='Infected')
        ax.plot(t, R, 'g', alpha=0.7, linewidth=2, label='Recovered')

        ax.set_xlabel('Time (days)')

        ax.yaxis.set_tick_params(length=0)
        ax.xaxis.set_tick_params(length=0)
        ax.grid(b=True, which='major', c='w', lw=2, ls='-')
        legend = ax.legend()
        legend.get_frame().set_alpha(0.5)
        for spine in ('top', 'right', 'bottom', 'left'):
            ax.spines[spine].set_visible(False)
            st.pyplot()

    if st.button("Show Plot SIR"):
        st.text("Enjoy")
        plotsir(t, S, I, R)

t = np.linspace(0, 49, 50)