gpt4 book ai didi

wolfram-mathematica - Mathematica 中 .csv 的日期和时间图

转载 作者:行者123 更新时间:2023-12-01 13:24:22 24 4
gpt4 key购买 nike

我想绘制一个图表,横轴为日期和时间,纵轴为整数值。我拥有的数据采用 .csv 格式,请参阅 file .

我试过

db = Dataset[
Flatten[Import[
"C:\\Users\\Matteo\\AppData\\Roaming\\MetaQuotes\\Terminal\\\
C10F84FF203255BEE7679EDC837848E1\\MQL4\\Files\\Data\\date_box.csv"]]]

DateListPlot[db]

但结果是错误:

"The first two levels of \
{$Failed,$Failed,$Failed,$Failed,$Failed,$Failed,$Failed,$Failed,$\<<9951>>} cannot be transposed. "

Unable to automatically determine horizontal coordinates for the \
given data and DataRange.

"\!\(TraditionalForm\`{\"2018.02.02 21:59;0\", \"2018.02.02 \
21:59;0\", \"2018.02.02 21:58;0\", ...\) is not a \
valid dataset or list of datasets."

我无法修复它

最佳答案

data = Import["C:\\Users\\Matteo\\...\\Files\\Data\\date_box.csv"];
d2 = StringSplit[#, ";"] & /@ Flatten[data];
t = DateList /@ d2[[All, 1]];
i = ToExpression /@ Last /@ d2;
DateListPlot[Transpose[{t, i}]]

enter image description here

删除周末

days = Take[#, 3] & /@ t;
union = {#, DateString[#, "DayNameShort"]} & /@ Union[days]

看起来你在周日有一些数据点

sundaypos = Position[days, {2018, 1, 28}];
Extract[i, sundaypos]

删除它们

tnew = Delete[t, sundaypos];
inew = Delete[i, sundaypos];

调整绘图以消除周末

t1 = AbsoluteTime[{2018, 1, 24}];
t2 = AbsoluteTime[{2018, 1, 27}];
t3 = AbsoluteTime[{2018, 1, 29}];

a = AbsoluteTime /@ tnew;
a2 = If[# >= t2, # - (t3 - t2), #] & /@ a;

labels = {AbsoluteTime[First[#]], Last[#]} & /@
DeleteCases[union, {{2018, 1, 28}, "Sun"}];
labels[[All, 1]] = If[# >= t2, # - (t3 - t2), #] & /@
labels[[All, 1]];

ListLinePlot[Sort@Transpose[{a2, inew}], Frame -> True,
FrameTicks -> {{Automatic, None}, {labels, None}}]

enter image description here

版本 3

{t1, t2, t3, t4, t5} = AbsoluteTime /@ {{2018, 1, 24},
{2018, 1, 26, 22, 0, 0}, {2018, 1, 28, 22, 0, 0},
{2018, 2, 2, 22, 0, 0}, {2018, 2, 4, 22, 0, 0}};

a = AbsoluteTime /@ t;
a2 = Which[
# >= t4, # - (t3 - t2) - (t5 - t4),
# >= t2, # - (t3 - t2),
True, #] & /@ a;

labels = {AbsoluteTime[#],
DateString[#, {"MonthNameShort", " ", "Day", "\n00:00"}]} & /@
Append[DeleteCases[union,
{{2018, 1, 28}, "Sun"}], {{2018, 2, 5}, "Mon"}][[All, 1]];

labels[[All, 1]] = Which[
# >= t4, # - (t3 - t2) - (t5 - t4),
# >= t2, # - (t3 - t2),
True, #] & /@ labels[[All, 1]];

ListPlot[Sort@Transpose[{a2, i}], Frame -> True,
FrameTicks -> {{Automatic, None}, {labels, None}},
Epilog -> {Dashed, Gray, Line[{{t2, 100}, {t2, -800}}],
Line[{{t4 - (t3 - t2), 100}, {t4 - (t3 - t2), -800}}]},
ImageSize -> Large]

enter image description here

关于wolfram-mathematica - Mathematica 中 .csv 的日期和时间图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48720425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com