通过午夜的日期时间绘制库存数据点

时间:2020-09-07 15:07:04

标签: python dataframe matplotlib

我的jupyter笔记本应用程序中有这种数据点(请在下面找到该数据点):

因此,该数据点基本上是一个原始OHLC的每15分钟一个数据点,并经过一些计算,并且每天从美国东部标准时间9.30-16.00开始。

但是,如果我尝试绘制图表,则matplotlib会从16.00-9.30推断数据,因此图表变为: enter image description here

这是我为情节编写的代码:

plt.figure(figsize=(10,8))
plt.plot(df_plot.index.to_pydatetime(), df_plot['open'], label="open", marker ="o")
plt.plot(df_plot.index.to_pydatetime(), df_plot['vwap'], label="vwap", marker ="o")


plt.legend()

plt.figure(figsize=(11,2))
plt.plot(df_plot.index.to_pydatetime(), df_plot['RSI'], marker ="o", color="red")

plt.figure(figsize=(11,2))
plt.plot(df_plot.index.to_pydatetime(), df_plot['macd'], label="macd", marker ="o")
plt.plot(df_plot.index.to_pydatetime(), df_plot['zero_line'], label="zero_line", marker ="o")

如何从图表中删除推断的数据? 这是数据点的副本:

date,open,low,high,close,volume,RSI,short_ema,long_ema,macd,zero_line,vwap
2020-09-03 09:30:00,90.22,90.22,90.22,90.22,50366918,44.92592908806629,90.35049697737522,90.50194327430559,-0.1514462969303736,-0.169148477316262,90.22
2020-09-03 09:45:00,87.5562,86.95,88.2,87.2,5363054,16.814815160281114,89.8658051347021,90.25735488361629,-0.39154974891418703,-0.213628731635847,89.96365493588979
2020-09-03 10:00:00,87.2,87.03,87.9517,87.1866,8363496,16.762458843062078,89.45361972936331,90.02989155890397,-0.5762718295406586,-0.28615735121680935,89.6030282180206
2020-09-03 10:15:00,87.1866,86.765,87.959,86.765,11210701,15.098442910586058,89.03998592484588,89.7880477397259,-0.7480618148800176,-0.378538243949451,89.24328911459602
2020-09-03 10:30:00,86.765,85.17,86.85,85.7692,17539479,11.947038944423127,88.5367880902542,89.49035531456101,-0.9535672243068092,-0.49354404002092267,88.7751052289156
2020-09-03 10:45:00,85.7692,84.6783,85.921,84.7103,21995802,9.559975138761104,87.94809761483049,89.13627714311204,-1.1881795282815517,-0.6324711376730485,88.19936843945874
2020-09-03 11:00:00,84.7999,83.82,84.9338,84.68,26682679,9.498878644599586,87.44531336639503,88.80618253991855,-1.3608691735235254,-0.778150744843144,87.55843033471395
2020-09-03 11:15:00,84.68,83.61,84.69,83.95,30316566,8.096433083253942,86.90757284848809,88.4464653147394,-1.538892466251312,-0.9302990891247777,87.05060453204034
2020-09-03 11:30:00,83.95,82.38,83.95,83.4601,35228246,7.284449057722128,86.37719241025916,88.077104921055,-1.6999125107958406,-1.0842217734589903,86.52309947171577
2020-09-03 11:45:00,83.4601,82.57,84.11,84.02,39634638,17.874268509811813,86.01454742406544,87.77657863060648,-1.7620312065410388,-1.2197836600754002,86.0310034107674
2020-09-03 12:00:00,84.58,83.63,84.6266,83.88,43084597,17.317851901791656,85.68615551267075,87.48794317648749,-1.8017876638167394,-1.3361844608236682,85.81527228769774
2020-09-03 12:15:00,83.88,83.21,84.0199,83.29,45925792,15.090664912612326,85.3175162030291,87.1769844226736,-1.8594682196444978,-1.440841212587834,85.5505247629739
2020-09-03 12:30:00,83.29,82.86,83.5253,83.09,48269174,14.385147889524319,84.97482140256308,86.87424483580888,-1.8994234332458007,-1.5325576567194275,85.26636064348884
2020-09-03 12:45:00,83.09,82.51,83.1984,82.7065,50915823,13.06727907052047,84.62584887909183,86.56552299611934,-1.9396741170275078,-1.6139809487810437,85.01156191591427
2020-09-03 13:00:00,82.7065,82.495,83.0981,82.64,53111716,12.837844549191729,84.32033366692386,86.27474351492532,-1.9544098480014611,-1.6820667286251274,84.76069385022826
2020-09-03 13:15:00,82.505,82.455,83.095,83.06,55363943,22.505568903136805,84.12643617970481,86.0366143656716,-1.9101781859667852,-1.7276890200934591,84.53086242289177
2020-09-03 13:30:00,83.06,82.5284,83.38,83.3501,57643035,28.654685335788116,84.00699984436561,85.83761330154778,-1.8306134571821673,-1.7482739075112008,84.3897929301867
2020-09-03 13:45:00,83.3501,82.81,83.37,82.83,59916273,24.701421371614956,83.82592294523243,85.61482713106275,-1.7889041858303187,-1.7563999631750244,84.29554037190474
2020-09-03 14:00:00,82.83,82.6399,83.067,82.82,61659345,24.627927064914914,83.67116556904284,85.40780289913218,-1.7366373300893372,-1.7524474365578873,84.17048453151615
2020-09-03 14:15:00,83.3067,82.85,83.325,82.8856,63646954,26.247369918107424,83.55030932765163,85.22097305475202,-1.67066372710039,-1.7360906946663879,84.10056010889758
2020-09-03 14:30:00,82.8856,82.5303,82.92,82.81,65783234,25.536027059260405,83.43641558493599,85.04238245810373,-1.6059668731677448,-1.7100659303666592,84.00675495441796
2020-09-03 14:45:00,82.81,82.81,83.48,83.1599,68354644,34.744450923386864,83.39387472571507,84.90293931305901,-1.5090645873439428,-1.669865661762116,83.91787416094174
2020-09-03 15:00:00,83.1599,82.4809,83.36,82.485,70608521,27.39361867425582,83.25404784483582,84.72383269727686,-1.4697848524410375,-1.6298494998979003,83.8638678395114
2020-09-03 15:15:00,82.485,81.8602,82.575,82.3,73877994,25.71583301159903,83.10727125332261,84.54428953451561,-1.437018281193005,-1.5912832561569215,83.76820480497689
2020-09-03 15:30:00,82.06,81.6299,82.1,81.69,76389993,20.954978396653416,82.88922952204221,84.33286068010705,-1.4436311580648322,-1.5617528365385036,83.65386574353599
2020-09-03 15:45:00,81.69,81.67,82.54,82.515,79381968,38.327177028174894,82.83165574942034,84.19820433343244,-1.3665485840121079,-1.5227119860332246,83.52614895628005
2020-09-03 16:00:00,82.515,82.1,82.645,82.52,83243560,38.41945379699735,82.78370871104796,84.07389290132633,-1.2901841902783673,-1.4762064268822532,83.46159412104963
2020-09-04 09:30:00,82.54,82.54,82.54,82.54,87462687,38.83130494429056,82.74621506319444,83.96027120493179,-1.2140561417373448,-1.4237763698532717,82.54
2020-09-04 09:45:00,82.54,81.39,84.38,82.33,8462229,35.988164811742564,82.68218197654915,83.83951037493684,-1.1573283983876905,-1.3704867755601555,82.54
2020-09-04 10:00:00,82.33,79.39,82.37,79.79,16330904,18.02757621923864,82.2372309032339,83.53954664346004,-1.302315740226149,-1.3568525684933541,82.5094493359899
2020-09-04 10:15:00,80.71,79.0438,81.0953,79.145,21244054,15.778042505000585,81.76150307196714,83.21402466987041,-1.4525215979032708,-1.3759863743753376,82.22310001056631
2020-09-04 10:30:00,79.145,77.73,79.44,77.73,26643720,12.063026457881719,81.14127183012604,82.80780062025038,-1.6665287901243317,-1.4340948575251364,81.71098439754013
2020-09-04 10:45:00,77.73,76.4077,78.085,76.6301,31402827,10.003336957758052,80.44724539472203,82.3501931668985,-1.902947772176475,-1.5278654404554042,81.05832712692659
2020-09-04 11:00:00,76.6301,76.4,78.65,78.4354,35348731,31.57595756133007,80.13773071861094,82.06020848786898,-1.9224777692580375,-1.606787906215931,80.36843927283691
2020-09-04 11:15:00,78.4901,78.4901,78.85,78.85,38137826,35.56640244975512,79.93961830036311,81.82241526654535,-1.8827969661822408,-1.661989718209193,80.09814922479457
2020-09-04 11:30:00,78.85,78.17,79.1271,78.43,40992886,33.349845327052535,79.70736933107648,81.57112524680124,-1.8637559157247665,-1.7023429577123077,79.93095669337183
2020-09-04 11:45:00,78.43,78.43,79.8401,79.67,43769985,44.780178842771086,79.70162020321855,81.4303011544456,-1.728680951227048,-1.707610556415256,79.74314185182253
2020-09-04 12:00:00,79.67,79.575,81.0721,81.0721,47387158,54.66934290481264,79.91246324887724,81.40376773559777,-1.491304486720523,-1.6643493424763094,79.7344154349627
2020-09-04 12:15:00,81.0721,80.3101,81.29,80.58840000000001,50114504,51.11650526657886,80.01645351828074,81.34337012555349,-1.32691660727275,-1.5968627954355976,79.88428749290335
2020-09-04 12:30:00,80.62,80.53,81.475,81.475,52081304,56.89322387637743,80.24084528469908,81.35312048662361,-1.1122752019245326,-1.4999452767333847,79.96101655226224
2020-09-04 12:45:00,81.475,80.9,81.72,80.9501,54269803,52.74199314469617,80.34996139474538,81.32326711724409,-0.9733057224987078,-1.3946173658864494,80.10942039683572
2020-09-04 13:00:00,80.9501,79.99,81.04,80.275,56252658,47.70549379636256,80.33842887247687,81.24561770115193,-0.9071888286750607,-1.2971316584441717,80.18695829364833
2020-09-04 13:15:00,80.275,79.6301,80.3382,79.74,57963793,43.96270876221897,80.24636289209582,81.13409046402957,-0.8877275719337518,-1.2152508411420877,80.19459940482365
2020-09-04 13:30:00,79.74,79.4057,79.86,79.635,59731959,43.21412525490964,80.1523070625426,81.02304672595331,-0.8707396634107027,-1.1463486055958108,80.15727914104386
2020-09-04 13:45:00,79.64,79.46,80.39,80.0901,61208769,47.56750353421526,80.14273674522836,80.95393956106787,-0.8112028158395077,-1.0793194476445502,80.1171399590385
2020-09-04 14:00:00,80.0901,79.92,80.54,80.43,62602960,50.740522983079295,80.18693109211631,80.915129223211,-0.7281981310946861,-1.0090951843345775,80.115151746608
2020-09-04 14:15:00,80.43,80.14,80.52,80.1727,63739207,48.25370495921415,80.18474169332919,80.8601344659361,-0.6753927726069122,-0.9423547019890444,80.13708063547186
2020-09-04 14:30:00,80.1727,80.07,80.9213,80.88,65066354,55.06446226162175,80.29170450974007,80.86160598697786,-0.5699014772377922,-0.8678640570387939,80.13944503898963
2020-09-04 14:45:00,81.365,81.26,81.52,81.26,67290159,58.375736621081735,80.44067304670314,80.89111665460914,-0.4504436079059957,-0.7843799672122344,80.21817290125692
2020-09-04 15:00:00,81.26,81.26,82.1701,82.058,69459702,64.54767718762426,80.68949257797958,80.97755245797141,-0.2880598799918346,-0.6851159497681544,80.28296011751216
2020-09-04 15:15:00,82.058,81.78,82.63,82.185,72324866,65.46451822796547,80.9195706429058,81.0669930166402,-0.14742237373440048,-0.5775772345614036,80.3909065601245
2020-09-04 15:30:00,82.185,82.0901,83.2001,83.02,75100603,71.00993097658241,81.24271362092028,81.21166020059277,0.031053420327509684,-0.45585110358362096,80.49746983307293
2020-09-04 15:45:00,83.02,81.83,83.02,82.095,77692708,59.16935173701294,81.37383460231716,81.27709277832665,0.0967418239905129,-0.3453325180687942,80.64349827820082
2020-09-04 16:00:00,82.12,82.06,82.4373,82.0699,80460197,58.869690806302934,81.48092158657606,81.33581923919134,0.1451023473847215,-0.2472455449780911,80.72701045093426

1 个答案:

答案 0 :(得分:1)

  • 如果要以均匀的间隔表示时间序列数据,而没有间隙,则必须将日期表示为字符串以进行绘图。
    • df.index.astype(str)
plt.figure(figsize=(10, 8))
plt.plot(df.index.astype(str), 'open', marker='o', data=df, label='open')
plt.plot(df.index.astype(str), 'vwap', marker='o', data=df, label='vwap')
plt.xticks(rotation=90)
plt.legend()
plt.show()

enter image description here

相关问题