-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathss-texplots-examples.tex
More file actions
165 lines (153 loc) · 4.25 KB
/
Copy pathss-texplots-examples.tex
File metadata and controls
165 lines (153 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
\documentclass[12pt]{article}
\usepackage[font=footnotesize]{caption}
\usepackage[font=footnotesize]{subcaption}
\usepackage[margin=1in]{geometry}
\input{ss-texplots}
\pgfplotstableread{
Criterion Rapperswil erap Palermo Jeddah
A 3620 500 15749 42754
B 2739 400 15109 42240
C 3710 350 16146 40533
D 714 160 9306 28919
E 2997 900 6840 11614
F 1589 440 4992 11786
G 2122 220 11154 28747
}\datatable
\pgfplotstableread{
Time J1 J2 J3
0 1.1 2.1 0.3
1 1.3 2.3 0.8
1.5 3.4 4.2 4.3
2.4 6.1 3.2 5.4
2.9 4.3 7.3 3.3
6.3 7.2 9.1 2.1
}\timetable
\title{Sidd's PGFPlots examples}
\author{Siddhartha S.~Srinivasa}
\begin{document}
\maketitle
\begin{figure}[t!]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
sidd ybar,
scaled y ticks=base 10:-3,
ylabel={Wattage (kWh)},
xtick=data,
xticklabels from table={\datatable}{Criterion}
]
\addplot table [x expr=\coordindex, y=Jeddah] {\datatable};
\addplot plot [select row={4}] table [x expr=\coordindex, y=Jeddah] {\datatable};
\end{axis}
\end{tikzpicture}
\caption{Vanilla barplot}
\label{fig:ybar-vanilla}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\centering
\begin{tikzpicture}
\pgfplotstablegetrowsof{\datatable}
\pgfmathtruncatemacro{\rows}{\pgfplotsretval}
\pgfmathtruncatemacro{\lastrow}{\rows-1}
\begin{axis}[
sidd ybar,
scaled y ticks=base 10:-3,
ylabel={Wattage (kWh)},
xtick=data,
xticklabels from table={\datatable}{Criterion},
xtick={0,...,\lastrow},
legend columns=1,
legend style={
at={(1.05,0)},anchor=south west,
/tikz/every even column/.append style={column sep=5pt}
},
]
\pgfplotsinvokeforeach {0,...,\lastrow}{
\addplot plot [sidd errorbars, error bars/.cd, y dir=both, y explicit]
table [ x expr=\coordindex, select row=#1, y=Rapperswil, y error = erap] {\datatable};
\addlegendentry {\pgfplotstablegetelem{#1}{Criterion}\of\datatable \pgfplotsretval};
}
\end{axis}
\end{tikzpicture}
\caption{Qualitative coloring}
\label{fig:ybar-qualitative}
\end{subfigure}
\begin{subfigure}[b]{0.35\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
sidd ybar,
scaled y ticks=base 10:-3,
ylabel={Wattage (kWh)},
xtick=data,
xticklabels from table={\datatable}{Criterion}
]
\pgfplotstablegetcolumnnamebyindex{1}\of{\datatable}\to{\colname} %Autoget column from index
\addplot table [ x expr=\coordindex, y=\colname] {\datatable};
\addplot table [ x expr=\coordindex, y=Palermo] {\datatable};
\addplot table [ x expr=\coordindex, y=Jeddah] {\datatable};
\end{axis}
\end{tikzpicture}
\caption{Stacked barplot}
\label{fig:ybar-stacked}
\end{subfigure}
\caption{Barplots with Colorbrewer colors.}
\label{fig:ybar}
\end{figure}
\begin{figure}[t!]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
sidd plot,
xlabel={Time (s.)},
ylabel={Torque (N)},
]
\addplot table [ x=Time, y=J1] {\timetable};
\end{axis}
\end{tikzpicture}
\caption{Vanilla XY plot}
\label{fig:xy-vanilla}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
sidd plot,
xlabel={Time (s.)},
ylabel={Torque (N)},
clip=false
]
\pgfplotstablegetcolumnnamebyindex{0}\of{\timetable}\to{\xaxis}
\pgfplotstablegetcolsof{\datatable}
\pgfmathtruncatemacro{\tcols}{\pgfplotsretval}
\pgfmathtruncatemacro{\cols}{\tcols-2}
\pgfplotstablegetrowsof{\timetable}
\pgfmathtruncatemacro{\rows}{\pgfplotsretval}
\pgfmathtruncatemacro{\lastrow}{\rows-1}
\pgfplotstablegetelem{\lastrow}{\xaxis}\of{\timetable}
\pgfmathsetmacro{\xn}{\pgfplotsretval}
\pgfplotsinvokeforeach{1,...,\cols}{
\pgfplotstablegetcolumnnamebyindex{#1}\of{\timetable}\to{\colname}
\pgfplotstablegetelem{\lastrow}{\colname}\of{\timetable}
\pgfmathsetmacro{\yn}{\pgfplotsretval}
\edef\doplot{
\noexpand\addplot
table [ x=\xaxis, y=\colname] {\noexpand\timetable}
node[anchor=west] at (axis cs:\xn,\yn) {\noexpand\footnotesize{\colname}};
}
\doplot
}
\end{axis}
\end{tikzpicture}
\caption{Multi XY plot}
\label{fig:ybar-vanilla}
\end{subfigure}
\caption{XY Plots}
\label{fig:xyplots}
\end{figure}
\end{document}