其中一行出现在Vizualisation中
%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
我想在可视化中同时获得hlines和vlines
答案 0 :(得分:0)
您的问题来自日期时间单位和非日期时间值的混合。
在取消注释def k_min(values, k):
minima = [] # len(minima) <= k + 1
for v in values:
minima.append(v)
if len(minima) > k:
minima.remove(max(minima)) # O(k) == O(1)
return minima
的同时运行代码时,您应该收到异常:
plt.vlines(hcoord,0,4)
ValueError:视图下限最小值-36865.76180555556小于1且 是无效的Matplotlib日期值。如果您通过了 具有日期时间单位的轴的非datetime值
用日期时间值替换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()
时,按预期工作:
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]
数组,以获取所需的绘图。