Tikz| How to change line color and style

colordrawtikz-pgf

I want to know how to change the color and the style of line in my graph, it's possible for marks but not for lines. this is my code :

    \begin{minipage}[b]{.48\linewidth}
    \begin{tikzpicture}[y=.1714cm, x=.5cm,font=\sffamily]
    %axis
    \draw (1,0) -- coordinate (x axis mid) (9,0);
    \draw (1,0) -- coordinate (y axis mid) (1,35);
  %ticks
  \draw (1.5,1pt) -- (1.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {20$\times$10};
    \draw (2.5,1pt) -- (2.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {20$\times$20};
    \draw (3.5,1pt) -- (3.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {40$\times$20};
    \draw (4.5,1pt) -- (4.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {40$\times$40};
    \draw (5.5,1pt) -- (5.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {60$\times$30};
    \draw (6.5,1pt) -- (6.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {60$\times$60};
    \draw (7.5,1pt) -- (7.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {80$\times$40};
    \draw (8.5,1pt) -- (8.5,-3pt) node[anchor=north, rotate = 45, above=-.7cm] {80$\times$80};
  \foreach \y in {2,6,10,14,18,22,26,30,34}
        \draw (0.9,\y) -- (1.1,\y) node[anchor=east] {\y}; 
    %labels      
    \node[below=1.5cm] at (x axis mid) {Instances};
    \node[rotate=90, left=1cm] at (y axis mid) {CPU time [in hundreds of seconds]};
    %plots
    \draw plot[mark=*, mark options={fill=white}] file {f_3_2.data};
    \draw plot[mark=triangle*, mark options={fill=black} ] file {q_3_2.data};
    %legend
    \begin{scope}[shift={(2,24)}] 
    \draw (0,0) -- 
        plot[dashed, mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0) 
        node[right]{Algo. LOQ};
    \draw[yshift=\baselineskip] (0,0) -- 
        plot[mark=triangle*, mark options={fill=black}] (0.25,0) -- (0.5,0)
        node[right]{Algo. \cite{Ref9}};
    \end{scope}
\end{tikzpicture}

i get this :

my graph

when i try to change the lines color or style by the following code, it doesn't work and without catching errors :

\draw plot[style=dashed, draw=red, mark=*, mark options={fill=white}] file {f_3_2.data};

even the position of the coordinates label can't be changed !

Thank you for helping me.

Best Answer

I would rather use pgfplots package. It has extensive package manual, which is part of package installation or you can find in CTAN by googling for Manual for Package pgfplots.

An uncomplete example (since your data table is not known), can be:


\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    axis lines = left,
    xtick = {0,1,...,9},
    xticklabels = { ,
                    $20\times10$, $20\times20$, $40\times20$, $40\times20$,
                    $60\times30$, $60\times60$, $80\times40$, $40\times80$},
    x tick label style = {rotate=45, anchor=east},
    xmin=0, xmax=9.5, xlabel = {instances},
    ymin=0, ymax=35,  ylabel={CPU time [in hundreds of seconds]},
    legend pos={north west},
every axis plot post/.append style={thick}
             ]%axis
\addplot coordinates { (1,2)  (2,6)  (3,10)
                       (4,14) (5,18) (6,22)
                       (7,26) (8,30) (9,34)};
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

An example, how to use table of diagram's data, see this answer.

Related Question