我如何才能改变传奇的图片?我想用线条代替……
\documentclass[margin=5mm]{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
axis equal image,
%unit vector ratio={1 1},
scale=0.6,
%width=4.5cm,
%height=3cm,
xlabel={$\theta$},
xtick={-1,-0.5,0.5,1},
xlabel style={anchor=west},
ylabel={$O(\theta^3)$},
ylabel style={anchor=south},
ytick={-0.5,0.5},
xmin=-1.25, xmax=1.25,
ymin=-0.7, ymax=0.7,
samples=500,
every tick/.style={black,line width=0.5pt},
legend style={
anchor=outer north east,
nodes={scale=0.9,inner sep=1pt, transform shape}
},
]
\addplot[mesh,
colormap={}{
color=(white)
color=(blue)
color=(white)
},
point meta=x,
thick,
%forget plot,
domain=-1.1:1.1] {cos(deg(x))-1};
\addlegendentry{\(\sin(\theta)-\theta\)}
\addplot[mesh,
colormap={}{
color=(white)
color=(red)
color=(white)
},
point meta=x,
thick,
%forget plot,
domain=-1.1:1.1] {sin(deg(x))-x};
\addlegendentry{\(\cos(\theta)-1\)}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
一种可能性是简单地使用这个传奇的答案。
\documentclass[margin=5mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{%
mesh line legend/.style={legend image code/.code=\meshlinelegend#1},%
}
\makeatletter
\long\def\meshlinelegend#1{%
\scope[%
#1,
/pgfplots/mesh/rows=1,
/pgfplots/mesh/cols=4,
/pgfplots/mesh/num points=,
/tikz/x={(0.44237cm,0cm)},
/tikz/y={(0cm,0.23932cm)},
/tikz/z={(0.0cm,0cm)},
scale=0.4,
]
\let\pgfplots@metamax=\pgfutil@empty
\pgfplots@curplot@threedimtrue
\pgfplotsplothandlermesh
\pgfplotstreamstart
\def\simplecoordinate(##1,##2,##3){%
\pgfmathparse{1000*(##3)}%
\pgfmathfloatparsenumber\pgfmathresult
\let\pgfplots@current@point@meta=\pgfmathresult
\pgfplotstreampoint{\pgfqpointxyz@orig{##1}{##2}{##3}}%
}%
\pgfplotsforeachungrouped \x in {0,...,\pgfkeysvalueof{/pgfplots/samples}}{
\pgfmathsetmacro\y{\x/\pgfkeysvalueof{/pgfplots/samples}}
\pgfmathsetmacro\x{\x/\pgfkeysvalueof{/pgfplots/samples}*3}
\simplecoordinate(\x,0,\y)
}
\pgfplotstreamend
\pgfusepath{stroke}
\endscope
}%
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
axis equal image,
%unit vector ratio={1 1},
scale=0.6,
%width=4.5cm,
%height=3cm,
xlabel={$\theta$},
xtick={-1,-0.5,0.5,1},
xlabel style={anchor=west},
ylabel={$O(\theta^3)$},
ylabel style={anchor=south},
ytick={-0.5,0.5},
xmin=-1.25, xmax=1.25,
ymin=-0.7, ymax=0.7,
samples=500,
every tick/.style={black,line width=0.5pt},
legend style={mesh line legend,
anchor=south east,
xshift=20pt,
nodes={scale=0.9,inner sep=1pt, transform shape}
},
]
\addplot[mesh,mesh line legend,
colormap={}{
color=(white)
color=(blue)
color=(white)
},
point meta=x,
thick,
%forget plot,
domain=-1.1:1.1] {cos(deg(x))-1};
\addlegendentry{\(\sin(\theta)-\theta\)}
\addplot[mesh,mesh line legend,
colormap={}{
color=(white)
color=(red)
color=(white)
},
point meta=x,
thick,
%forget plot,
domain=-1.1:1.1] {sin(deg(x))-x};
\addlegendentry{\(\cos(\theta)-1\)}
\end{axis}
\end{tikzpicture}
\end{document}