Python 如何在Vizalization中同时获得hline和vline

Python 如何在Vizalization中同时获得hline和vline,python,pandas,numpy,matplotlib,data-visualization,Python,Pandas,Numpy,Matplotlib,Data Visualization,其中一行出现在Vizalization中 %matplotlib import numpy as np import matplotlib as mpl import matplotlib.dates as mdates import matplotlib.pyplot as plt import pandas as pd def grid_sncf_generation_mitry(): plt.figure(figsize=(50,100)) # general var

其中一行出现在Vizalization中

%matplotlib

import numpy as np
import matplotlib as mpl
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import pandas as pd
def grid_sncf_generation_mitry():
    plt.figure(figsize=(50,100))


    # general var
    hcoord = np.arange(0,1,23)


    # Adding the time zone

    # J'ai restreint la plage horaire

    v2=np.datetime64('2019-09-13T03:30')
    v1=np.datetime64('2019-09-13T05:40')

    # Adding Stations V5 / V3 / SAS5 / SAS3

    plt.hlines("GA",v1,v2,"grey","dotted")
    plt.hlines("SAS3",v1,v2,"grey","dotted")
    plt.hlines("SAS5",v1,v2,"grey","dotted")
    plt.hlines("V3",v1,v2,"grey","dotted")
    plt.hlines("V5",v1,v2,"grey","dotted")

    #plt.vlines(hcoord,0,4)

    # id station
    plt.ylabel("MITRY")

    # Time axis
    # Adding Hours
    myFmt = mdates.DateFormatter('%H')
    plt.gca().xaxis.set_major_formatter(myFmt)
    plt.gca().xaxis.set_major_locator(mdates.HourLocator())

    # Adding Minutes
    myFmt2 = mdates.DateFormatter('%M')
    plt.gca().xaxis.set_minor_formatter(myFmt2)
    plt.gca().xaxis.set_minor_locator(mdates.MinuteLocator([10, 20, 30, 40, 50]))


    # Minimisize the police of minutes
    for tick in plt.gca().xaxis.get_minor_ticks():
        tick.label.set_fontsize(6)

    # comment détecter les heurs ?



    # comment détecter les 30's ?

    plt.show()
    return plt 

我想在可视化中同时获得hline和vline

您的问题来自混合日期时间单位和非日期时间值

%matplotlib

import numpy as np
import matplotlib as mpl
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import pandas as pd
def grid_sncf_generation_mitry():
    plt.figure(figsize=(50,100))


    # general var
    hcoord = np.arange(0,1,23)


    # Adding the time zone

    # J'ai restreint la plage horaire

    v2=np.datetime64('2019-09-13T03:30')
    v1=np.datetime64('2019-09-13T05:40')

    # Adding Stations V5 / V3 / SAS5 / SAS3

    plt.hlines("GA",v1,v2,"grey","dotted")
    plt.hlines("SAS3",v1,v2,"grey","dotted")
    plt.hlines("SAS5",v1,v2,"grey","dotted")
    plt.hlines("V3",v1,v2,"grey","dotted")
    plt.hlines("V5",v1,v2,"grey","dotted")

    #plt.vlines(hcoord,0,4)

    # id station
    plt.ylabel("MITRY")

    # Time axis
    # Adding Hours
    myFmt = mdates.DateFormatter('%H')
    plt.gca().xaxis.set_major_formatter(myFmt)
    plt.gca().xaxis.set_major_locator(mdates.HourLocator())

    # Adding Minutes
    myFmt2 = mdates.DateFormatter('%M')
    plt.gca().xaxis.set_minor_formatter(myFmt2)
    plt.gca().xaxis.set_minor_locator(mdates.MinuteLocator([10, 20, 30, 40, 50]))


    # Minimisize the police of minutes
    for tick in plt.gca().xaxis.get_minor_ticks():
        tick.label.set_fontsize(6)

    # comment détecter les heurs ?



    # comment détecter les 30's ?

    plt.show()
    return plt 
当您在取消对plt.vlines(hcoord,0,4)的注释时运行代码时,您应该会收到一个异常:

fig = plt.figure()
hcoord = np.arange(0,1,23)
v2=np.datetime64('2019-09-13T03:30')
v1=np.datetime64('2019-09-13T05:40')

# Adding Stations V5 / V3 / SAS5 / SAS3

plt.hlines("GA",v1,v2,"grey","dotted")
plt.hlines("SAS3",v1,v2,"grey","dotted")
plt.hlines("SAS5",v1,v2,"grey","dotted")
plt.hlines("V3",v1,v2,"grey","dotted")
plt.hlines("V5",v1,v2,"grey","dotted")

plt.vlines(hcoord,0,4)
plt.show()
ValueError:视图限制最小值-36865.76180555556小于1,并且 是无效的Matplotlib日期值。如果你通过考试,这种情况经常发生 具有日期时间单位的轴的非日期时间值

用日期时间值替换
hcoord
时,工作正常:

fig = plt.figure()
hcoord = np.arange(0,1,23)
v2=np.datetime64('2019-09-13T03:30')
v1=np.datetime64('2019-09-13T05:40')

# Adding Stations V5 / V3 / SAS5 / SAS3

plt.hlines("GA",v1,v2,"grey","dotted")
plt.hlines("SAS3",v1,v2,"grey","dotted")
plt.hlines("SAS5",v1,v2,"grey","dotted")
plt.hlines("V3",v1,v2,"grey","dotted")
plt.hlines("V5",v1,v2,"grey","dotted")

plt.vlines(v2,0,4)
plt.show()


不幸的是,我不明白您试图用
hccord=np.arange(0,1,23)
绘制什么,因为此指令返回
[0]
。您必须找出如何以日期时间单位生成正确的
hcoord
数组,以获得所需的绘图。

您的代码没有任何未注释的调用
plt.vlines
。具体来说,当你尝试这样做时会出现什么问题?问题是当我从plt.vlines(hcoord,0,4)中删除#时,我只得到一条垂直线,而水平线消失了。Diziet,你就是那个人!泰:你把我想做的东西修好了吗。我不知道HCOORD的值是什么。如果你的问题被解决了,请考虑点击左边的检查标记来关闭主题。