I'm writing some app, which generates a TeX code. My program creates variable number of plots and I'd like to use visualize them using pgfplots
.
In the old version of this app (not created by me), plots are generated with gnuplot
and they look like this:
In contrast, my plot is looking like this now:
The first problem is, it appears, that pgfplots
automatically use lesser number of colors for plots that gnuplot
, so when I add more plots to the picture, it just keeps switching between blue, red and black, solid, dashed etc. The problem is, when we have multiple plots, just 3 colors make them undifferentiable.
On the other hand, gnuplot
seems to have a very nice ability to automatically differentiate them visually from each other.
Is there any way to get similar behavior with pgfplots
? I can't set the color of each plot manually, because I simply don't know, how many of the will be there - app must work for arbitrary number of plots.
The second problem is the position of the plot itself in the paper. tikzpicture
tends to have a huge indent from the left side of the paper and I'm not able to align it to the left.
Because of the size of plots I really need to force this position to use most of the paper for the plot.
Is there any way how to do it?
My code
\begin{document}
\flushleft
\begin{tikzpicture}[scale=1, remember picture,overlay]
\begin{axis}[
title={ TEST graf },
xlabel={ Number of samples },
ylabel={ Power[W] },
legend pos=outer north east,
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
no markers,
width=18cm,
anchor=north west
]
\addplot table [x=ind, y=val, col sep=comma] {data0.csv};
\addplot table [x=ind, y=val, col sep=comma] {data1.csv};
\addplot table [x=ind, y=val, col sep=comma] {data2.csv};
\addplot table [x=ind, y=val, col sep=comma] {data3.csv};
\legend{ 0,1,2,3}
\end{axis}
\end{tikzpicture}
1st Attempt
After adding cycle list name = color list
, removing anchor = north east
and wrapping my tikzpicture
into adjustbox
environment with options valign=t, center
my code looks like this:
\begin{adjustbox}{valign=t, center}
\begin{tikzpicture}[scale=1]
\begin{axis}[
title={ TEST graf },
xlabel={ Number of samples },
ylabel={ Power[W] },
legend pos=outer north east,
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
no markers,
width=24cm,
height=15cm,
cycle list name = color list
]
\addplot table [x=ind, y=val, col sep=comma] {data0.csv};
\addplot table [x=ind, y=val, col sep=comma] {data1.csv};
\addplot table [x=ind, y=val, col sep=comma] {data2.csv};
\addplot table [x=ind, y=val, col sep=comma] {data3.csv};
\legend{ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 }
\end{axis}
\end{tikzpicture}
\end{adjustbox}
And the plot is much better:
The only remaining problem is, that valign
option is not working - the picture is not on the top of the page. What am I doing wrong this time?
cycle list
s in the manual, see section 4.7.7 Cycle Lists – Options Controlling Line Styles. Regarding the horizontal alignment of the plot, I'm guessing this has nothing to withtikzpicture
, but that your text block is narrower than 18cm (the width of youraxis
), so it sticks into the right margin. To get around that you can use the techniques in Center figure that is wider than \textwidth or How can I center a too wide table?remember picture,overlay
from the picture optionsadjustbox
- could you, please have a look at it? (description of the problem was added into the question)valign
does, it just sets the "anchor" of the box on the baseline, it's not relative to the page. Quick hack, try adding\vspace*{-3cm}
just before thetikzpicture
.adjustbox
stuff, and switch to using\documentclass{standalone}
. That will give you a page that is the size of thetikzpicture
, without needing to adjust anything.