I am having trouble forcing the two PGFPlots to appear side by side, can someone please fix my coding. I would also like to center the subcaptions better if possible. I cut most of the data to fit into this space. thanks in advance.
\begin{filecontents*}{ST0421.csv}
nm,0,2.3,3.5,5.2,7.8,11.7,17.6,26.3,39.5,59.3,88.9,133.3,200,300
380,0.102,0.102,0.101,0.103,0.101,0.104,0.105,0.103,0.101,0.111,0.105,0.103,0.103,0.101
381,0.105,0.104,0.104,0.106,0.105,0.105,0.103,0.103,0.103,0.113,0.109,0.106,0.107,0.106
382,0.108,0.109,0.108,0.108,0.106,0.106,0.108,0.106,0.106,0.117,0.109,0.111,0.107,0.103
383,0.103,0.105,0.105,0.105,0.103,0.104,0.104,0.104,0.105,0.111,0.105,0.105,0.105,0.102
384,0.109,0.107,0.109,0.108,0.108,0.108,0.109,0.108,0.108,0.115,0.109,0.112,0.107,0.105
385,0.109,0.11,0.109,0.111,0.108,0.11,0.112,0.11,0.112,0.12,0.112,0.11,0.112,0.108
386,0.113,0.117,0.116,0.118,0.114,0.114,0.116,0.116,0.112,0.123,0.116,0.114,0.114,0.112
387,0.119,0.121,0.119,0.12,0.12,0.119,0.124,0.12,0.119,0.125,0.12,0.12,0.12,0.117
388,0.124,0.122,0.123,0.122,0.123,0.122,0.122,0.122,0.121,0.129,0.124,0.124,0.122,0.117
389,0.131,0.127,0.13,0.131,0.128,0.128,0.133,0.13,0.126,0.135,0.13,0.127,0.128,0.124
390,0.139,0.136,0.136,0.136,0.138,0.139,0.14,0.137,0.136,0.141,0.139,0.138,0.132,0.13
391,0.143,0.143,0.142,0.143,0.138,0.143,0.144,0.141,0.141,0.147,0.145,0.14,0.143,0.135
392,0.152,0.151,0.151,0.15,0.147,0.149,0.151,0.15,0.151,0.156,0.152,0.149,0.15,0.143
393,0.154,0.15,0.155,0.153,0.15,0.153,0.153,0.153,0.154,0.158,0.153,0.151,0.151,0.144
394,0.16,0.158,0.159,0.161,0.158,0.158,0.164,0.16,0.159,0.164,0.162,0.159,0.159,0.151
\end{filecontents*}
\begin{figure}[!h]
\centering
\begin{subfigure}{.45\linewidth}\centering
\begin{tikzpicture}
\begin{axis}[
scale only axis,
width=\linewidth,
xlabel={nm},
ylabel={Abs},
xmin=385, xmax=595,
ymajorgrids=true,
grid style=dashed,
legend pos=north east,
cycle list name=color list,
legend columns=2,
legend cell align=left]
\addplot table [x=nm, y=0, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=2.3, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=3.5, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=5.2, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=7.8, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=11.7, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=17.6, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=26.3, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=39.5, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=59.3, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=88.9, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=133.3, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=200, col sep=comma] {ST0421.csv};
\addplot table [x=nm, y=300, col sep=comma] {ST0421.csv};
\legend{0 $\mu$M,2.3 $\mu$M,3.5 $\mu$M,5.2 $\mu$M,7.8 $\mu$M,11.7 $\mu$M,17.6 $\mu$M,26.3 $\mu$M,39.5 $\mu$M,59.3 $\mu$M,88.9 $\mu$M,133.3 $\mu$M,200 $\mu$M,300 $\mu$M}
\end{axis}
\end{tikzpicture}
\caption{uv spectra of st042 Por free base with Me-IMD in 5 mM buffer}
\end{subfigure}%
\hfill
\begin{filecontents*}{ST0422.csv}
nm,0,2.3,3.5,5.2,7.8,11.7,17.6,26.3,39.5,59.3,88.9,133.3,200
380,0.14,0.141,0.14,0.14,0.136,0.137,0.132,0.131,0.135,0.133,0.13,0.13,0.134
381,0.146,0.142,0.145,0.141,0.138,0.136,0.136,0.132,0.13,0.129,0.131,0.131,0.137
382,0.145,0.143,0.144,0.145,0.141,0.139,0.134,0.134,0.13,0.13,0.132,0.134,0.136
383,0.141,0.138,0.141,0.141,0.137,0.131,0.13,0.129,0.127,0.128,0.126,0.129,0.132
384,0.145,0.144,0.144,0.14,0.135,0.136,0.132,0.131,0.13,0.128,0.128,0.129,0.134
385,0.147,0.143,0.143,0.142,0.141,0.136,0.132,0.13,0.132,0.13,0.13,0.127,0.131
\end{filecontents*}
\begin{subfigure}{.45\linewidth}\centering
\begin{tikzpicture}
\begin{axis}[
scale only axis,
width=\linewidth,
xlabel={nm},
ylabel={Abs},
xmin=385, xmax=595,
ymajorgrids=true,
grid style=dashed,
legend pos=north east,
cycle list name=color list,
legend columns=2,
legend cell align=left]
\addplot table [x=nm, y=0, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=2.3, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=3.5, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=5.2, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=7.8, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=11.7, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=17.6, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=26.3, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=39.5, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=59.3, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=88.9, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=133.3, col sep=comma] {ST0422.csv};
\addplot table [x=nm, y=200, col sep=comma] {ST0422.csv};
\legend{0 $\mu$M,2.3 $\mu$M,3.5 $\mu$M,5.2 $\mu$M,7.8 $\mu$M,11.7 $\mu$M,17.6 $\mu$M,26.3 $\mu$M,39.5 $\mu$M,59.3 $\mu$M,88.9 $\mu$M,133.3 $\mu$M,200 $\mu$M,300 $\mu$M}
\end{axis}
\end{tikzpicture}
\caption{uv spectra of st042 Por-Co Me-IMD in 5 mM buffer}
\end{subfigure}
\end{figure}
\end{document}


subfigures, so they're placed in different paragraphs, and hence different lines. – Torbjørn T. Jun 26 '15 at 22:35scale only axis,width=\linewidth, which means that only the axis is\linewidthwide. Ticklabels and axis labels come in addition, so the whole thing is wider than thesubfigure, and therefore it pokes a bit out on the right side. – Torbjørn T. Jun 26 '15 at 22:42scale only axis, or by setting the width to something smaller than\linewidth. If you want to ignore the fact that it is too wide, you can use the\makeboxtrick in Center figure that is wider than \textwidth. Place the wholetikzpicturein the\makebox. – Torbjørn T. Jun 27 '15 at 10:12