TeX - LaTeX Asked by Patris on July 30, 2020
Consider the following code from PGFPlots Gallery which draws multiple plots with the names of d2, d3, d4, d5 and d6.
documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=newest}
pagestyle{empty}
begin{document}
begin{tikzpicture}
begin{loglogaxis}[
xlabel={Degrees of freedom},
ylabel={$L_2$ Error}
]
addplot coordinates {
(5,8.312e-02) (17,2.547e-02) (49,7.407e-03)
(129,2.102e-03) (321,5.874e-04) (769,1.623e-04)
(1793,4.442e-05) (4097,1.207e-05) (9217,3.261e-06)
};
addplot coordinates{
(7,8.472e-02) (31,3.044e-02) (111,1.022e-02)
(351,3.303e-03) (1023,1.039e-03) (2815,3.196e-04)
(7423,9.658e-05) (18943,2.873e-05) (47103,8.437e-06)
};
addplot coordinates{
(9,7.881e-02) (49,3.243e-02) (209,1.232e-02)
(769,4.454e-03) (2561,1.551e-03) (7937,5.236e-04)
(23297,1.723e-04) (65537,5.545e-05) (178177,1.751e-05)
};
addplot coordinates{
(11,6.887e-02) (71,3.177e-02) (351,1.341e-02)
(1471,5.334e-03) (5503,2.027e-03) (18943,7.415e-04)
(61183,2.628e-04) (187903,9.063e-05) (553983,3.053e-05)
};
addplot coordinates{
(13,5.755e-02) (97,2.925e-02) (545,1.351e-02)
(2561,5.842e-03) (10625,2.397e-03) (40193,9.414e-04)
(141569,3.564e-04) (471041,1.308e-04) (1496065,4.670e-05)
};
legend{$d2$,$d3$,$d4$,$d5$,$d6$}
end{loglogaxis}
end{tikzpicture}
end{document}
Now, I want to only have the plot d4. So, I removed the unneeded section as follows:
documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=newest}
pagestyle{empty}
begin{document}
begin{tikzpicture}
begin{loglogaxis}[
xlabel={Degrees of freedom},
ylabel={$L_2$ Error}
]
addplot coordinates{
(9,7.881e-02) (49,3.243e-02) (209,1.232e-02)
(769,4.454e-03) (2561,1.551e-03) (7937,5.236e-04)
(23297,1.723e-04) (65537,5.545e-05) (178177,1.751e-05)
};
legend{$d4$}
end{loglogaxis}
end{tikzpicture}
end{document}
As you can see, the final result for d4 in the above figures are different, e.g. d4 is green and blue in the first and second figure respectively. The reason is that in the first figure, d4 is the third plot, while in the second figure, d4 is the first plot. What I need is to have completely same addplot
settings for d4 in both figures. More precisely, d4 in the second figure must have same mark options and color as it has in the first figure, e.g. d4 should be also green in the second figure. I tried to manually add mark
and color
to addplot
command like addplot[color=green, mark options={fill=green}, ...]
, but at the end of the day, I could not get the desired output. So, I am thinking if we can find the default settings of addplot
for d4 in the first figure and use them in the second one.
This is determined by the default cycle list
, which is called color
, and is described in the pgfplots
manual, on the bottom of page 217 (in the manual for version 1.17, dated 29 Feb 2020), in the section called 4.7.7 Cycle Lists – Options Controlling Line Styles. There you'll find that the third entry in that cycle list is
brown!60!black,every mark/.append style={fill=brown!80!black},mark=otimes*black,mark=star
(The indicates the end of that entry in the list.)
Another option though is to use cycle list shift
, which lets you jump ahead in the cycle list without adding any plots. Add pgfplotsset{cycle list shift=2}
just before your addplot
:
documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=newest}
pagestyle{empty}
begin{document}
begin{tikzpicture}
begin{loglogaxis}[
xlabel={Degrees of freedom},
ylabel={$L_2$ Error}
]
pgfplotsset{cycle list shift=2}
addplot coordinates{
(9,7.881e-02) (49,3.243e-02) (209,1.232e-02)
(769,4.454e-03) (2561,1.551e-03) (7937,5.236e-04)
(23297,1.723e-04) (65537,5.545e-05) (178177,1.751e-05)
};
legend{$d4$}
end{loglogaxis}
end{tikzpicture}
end{document}
Answered by Torbjørn T. on July 30, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP