我想知道如何改变图表中线条的颜色和样式,标记可以但线条不行。这是我的代码:
\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}
我明白了:
当我尝试通过以下代码更改线条颜色或样式时,它不起作用并且没有捕获错误:
\draw plot[style=dashed, draw=red, mark=*, mark options={fill=white}] file {f_3_2.data};
甚至连坐标标签的位置也不能改变!
感谢你们对我的帮助。
答案1
我宁愿使用pgfplots
软件包。它有详尽的软件包手册,这是软件包安装的一部分,或者你可以在 CTAN 中通过谷歌搜索找到pgfplots 软件包手册。
一个不完整的例子(因为你的数据表未知)可以是:
\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}
如何使用图表数据的示例,请参阅这个答案。