如何使用 datatool 和 TikZ 将大数据值绘制并缩放为类似火花图的图表?

如何使用 datatool 和 TikZ 将大数据值绘制并缩放为类似火花图的图表?

我想按照尺寸++(1pt, 4pt)绘制(x, y)矩形X基于外部数据,但我不确定如何才能获得适当的图表。

明显的理想例子是
理想输出
但就像我在标题中说的那样,我并不严格追求“迷你图”,我想它也可以被称为散点图

这是.csv 文件中的文本。如您所见,我利用这个机会在 .csv 文件中包括了各种列和数据,并命名了标题,我发现这真的很有用。至少我认为这是可能的,我想继续这样做;我希望我在此过程中没有犯错误。我这样做是为了创建一些假数据,以便能够在 TikZ 中从中获得一些东西,因为它最初说尺寸太大了。

平均能量损失

\documentclass{scrartcl}

\usepackage{
tikz,
relsize,
amsmath
}
\usetikzlibrary{calc,trees,shadows,positioning,arrows,chains,shapes.geometric,shapes,matrix,shapes.symbols,patterns}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{
datatool,
databar
}

\DTLloaddb[noheader=false]{Zeitreihen-BalanceLargeBank-1999-2013}{Balance-of-Large-Bank-1999-01-to-2013-04.csv}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
    \DTLforeach*{Zeitreihen-BalanceLargeBank-1999-2013}{\x=xnum, \y=y}{\draw[fill=black] (\x*2 pt,\y cm) rectangle ++(1pt,4pt);}
    \DTLforeach*{Zeitreihen-BalanceLargeBank-1999-2013}{\x=xnum, \y=xjahr}{\draw (\x*2 pt,0) node[anchor=north] {\y};}
\end{tikzpicture}
\end{center}
\end{document}

答案1

如果您想要做的只是绘制数据,那么可以使用 PGFPlots 来完成(它负责缩放数据和创建轴,并允许您以多种方式呈现数据)。

要设置大约 10 厘米的整体宽度,请设置width=10cm。要删除顶部和右侧的轴线,请设置axis lines*=left。要使用xjahr列来绘制数据,您可以设置x coord trafo/.code将日期转换为纯数字:

\documentclass{scrartcl}

\usepackage{
pgfplots,
amsmath,
filecontents
}
\usetikzlibrary{calc,trees,shadows,positioning,arrows,chains,shapes.geometric,shapes,matrix,shapes.symbols,patterns}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\begin{filecontents}{data.csv}
xnum,xjahr,y,actually y/50000,,original values
1,1999-01,17.308,,,865387
2,1999-02,16.530,,,826493
3,1999-03,16.708,,,835423
4,1999-04,16.956,,,847800
5,1999-05,17.038,,,851910
6,1999-06,16.900,,,844993
7,1999-07,16.810,,,840493
8,1999-08,16.880,,,843976
9,1999-09,16.408,,,820417
10,1999-10,16.587,,,829335
11,1999-11,17.029,,,851461
12,1999-12,16.501,,,825069
13,2000-01,16.997,,,849872
14,2000-02,17.334,,,866708
15,2000-03,18.122,,,906082
16,2000-04,18.446,,,922312
17,2000-05,18.866,,,943315
18,2000-06,18.154,,,907699
19,2000-07,17.989,,,899459
20,2000-08,18.309,,,915436
21,2000-09,18.617,,,930840
22,2000-10,18.875,,,943742
23,2000-11,19.233,,,961654
24,2000-12,19.396,,,969783
25,2001-01,19.868,,,993401
26,2001-02,20.527,,,1026344
27,2001-03,21.668,,,1083414
28,2001-04,21.948,,,1097404
29,2001-05,22.027,,,1101367
30,2001-06,20.942,,,1047088
31,2001-07,20.442,,,1022115
32,2001-08,20.527,,,1026337
33,2001-09,20.555,,,1027772
34,2001-10,20.621,,,1031049
35,2001-11,20.664,,,1033212
36,2001-12,20.536,,,1026819
37,2002-01,20.245,,,1012261
38,2002-02,20.032,,,1001623
39,2002-03,20.462,,,1023104
40,2002-04,20.187,,,1009366
41,2002-05,20.773,,,1038632
42,2002-06,20.212,,,1010581
43,2002-07,20.116,,,1005803
44,2002-08,20.251,,,1012531
45,2002-09,20.849,,,1042436
46,2002-10,20.852,,,1042580
47,2002-11,21.794,,,1089675
48,2002-12,21.124,,,1056182
49,2003-01,21.169,,,1058460
50,2003-02,21.048,,,1052413
51,2003-03,21.109,,,1055453
52,2003-04,21.288,,,1064424
53,2003-05,22.035,,,1101768
54,2003-06,21.639,,,1081971
55,2003-07,21.261,,,1063031
56,2003-08,21.030,,,1051506
57,2003-09,21.220,,,1060986
58,2003-10,21.102,,,1055099
59,2003-11,20.989,,,1049437
60,2003-12,20.895,,,1044735
61,2004-01,21.137,,,1056866
62,2004-02,21.151,,,1057574
63,2004-03,21.567,,,1078342
64,2004-04,21.957,,,1097832
65,2004-05,21.791,,,1089546
66,2004-06,21.053,,,1052646
67,2004-07,21.183,,,1059131
68,2004-08,21.228,,,1061391
69,2004-09,21.660,,,1083010
70,2004-10,21.869,,,1093465
71,2004-11,22.445,,,1122244
72,2004-12,24.349,,,1217452
73,2005-01,25.029,,,1251463
74,2005-02,25.256,,,1262780
75,2005-03,24.728,,,1236378
76,2005-04,26.789,,,1339462
77,2005-05,26.458,,,1322900
78,2005-06,24.832,,,1241620
79,2005-07,24.915,,,1245746
80,2005-08,24.939,,,1246927
81,2005-09,24.593,,,1229663
82,2005-10,25.041,,,1252056
83,2005-11,25.655,,,1282731
84,2005-12,24.539,,,1226940
85,2006-01,25.302,,,1265120
86,2006-02,25.286,,,1264304
87,2006-03,25.412,,,1270592
88,2006-04,25.825,,,1291228
89,2006-05,26.252,,,1312608
90,2006-06,25.588,,,1279378
91,2006-07,25.074,,,1253699
92,2006-08,25.192,,,1259575
93,2006-09,25.749,,,1287470
94,2006-10,25.659,,,1282956
95,2006-11,26.107,,,1305365
96,2006-12,25.938,,,1296889
97,2007-01,26.266,,,1313293
98,2007-02,26.744,,,1337178
99,2007-03,26.880,,,1344000
100,2007-04,27.685,,,1384240
101,2007-05,28.065,,,1403246
102,2007-06,27.531,,,1376571
103,2007-07,27.465,,,1373268
104,2007-08,27.652,,,1382620
105,2007-09,28.396,,,1419808
106,2007-10,27.762,,,1388094
107,2007-11,28.321,,,1416058
108,2007-12,28.078,,,1403914
109,2008-01,28.779,,,1438948
110,2008-02,29.006,,,1450275
111,2008-03,29.265,,,1463257
112,2008-04,30.278,,,1513904
113,2008-05,30.187,,,1509339
114,2008-06,28.637,,,1431864
115,2008-07,28.864,,,1443179
116,2008-08,29.152,,,1457623
117,2008-09,29.991,,,1499535
118,2008-10,30.414,,,1520699
119,2008-11,30.121,,,1506038
120,2008-12,29.330,,,1466516
121,2009-01,29.655,,,1482739
122,2009-02,28.941,,,1447034
123,2009-03,28.822,,,1441075
124,2009-04,29.206,,,1460275
125,2009-05,27.943,,,1397169
126,2009-06,27.302,,,1365080
127,2009-07,26.964,,,1348188
128,2009-08,26.997,,,1349834
129,2009-09,26.586,,,1329284
130,2009-10,26.708,,,1335384
131,2009-11,26.768,,,1338391
132,2009-12,25.848,,,1292388
133,2010-01,26.179,,,1308947
134,2010-02,25.964,,,1298190
135,2010-03,25.594,,,1279697
136,2010-04,26.939,,,1346967
137,2010-05,27.497,,,1374860
138,2010-06,26.597,,,1329827
139,2010-07,26.217,,,1310865
140,2010-08,27.087,,,1354348
141,2010-09,25.695,,,1284736
142,2010-10,26.489,,,1324447
143,2010-11,27.365,,,1368229
144,2010-12,41.658,,,2082896
145,2011-01,40.145,,,2007247
146,2011-02,39.748,,,1987420
147,2011-03,37.512,,,1875608
148,2011-04,38.648,,,1932378
149,2011-05,39.539,,,1976959
150,2011-06,37.166,,,1858310
151,2011-07,39.240,,,1962024
152,2011-08,42.761,,,2138066
153,2011-09,44.646,,,2232276
154,2011-10,42.490,,,2124486
155,2011-11,42.414,,,2120717
156,2011-12,43.045,,,2152254
157,2012-01,43.541,,,2177035
158,2012-02,43.026,,,2151277
159,2012-03,42.252,,,2112619
160,2012-04,43.287,,,2164348
161,2012-05,47.271,,,2363567
162,2012-06,43.491,,,2174547
163,2012-07,45.590,,,2279517
164,2012-08,45.064,,,2253197
165,2012-09,43.462,,,2173093
166,2012-10,42.871,,,2143564
167,2012-11,42.915,,,2145738
168,2012-12,41.239,,,2061955
169,2013-01,40.208,,,2010401
170,2013-02,40.485,,,2024226
171,2013-03,40.116,,,2005807
172,2013-04,41.069,,,2053430
\end{filecontents}

\pgfplotstableread[col sep=comma]{data.csv}\datatable

\def\parsedate#1-#2!{%
    \pgfmathparse{#1+1/12*(1#2-101)}%
}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
    width=10cm, height=5cm,
    axis lines*=left,
    ymin=0,
    enlargelimits=upper,
    /pgf/number format/1000 sep={},
    x coord trafo/.code={\expandafter\parsedate#1!}
]
\addplot [no markers] table [x=xjahr, y=y] {\datatable};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

相关内容