Legendary entry
Legendary entry
How can i change the picture of the legendary? I would like to have to lines insted...
documentclass[margin=5mm]standalone
usepackagetikz,pgfplots
begindocument
begintikzpicture
beginaxis[
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)
endaxis
endtikzpicture
enddocument
1 Answer
1
One possibility is to simply use this legendary answer.
documentclass[margin=5mm]standalone
usepackagetikz,pgfplots
pgfplotsset%
mesh line legend/.style=legend image code/.code=meshlinelegend#1,%
makeatletter
longdefmeshlinelegend#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,
]
letpgfplots@metamax=pgfutil@empty
pgfplots@curplot@threedimtrue
pgfplotsplothandlermesh
pgfplotstreamstart
defsimplecoordinate(##1,##2,##3)%
pgfmathparse1000*(##3)%
pgfmathfloatparsenumberpgfmathresult
letpgfplots@current@point@meta=pgfmathresult
pgfplotstreampointpgfqpointxyz@orig##1##2##3%
%
pgfplotsforeachungrouped x in 0,...,pgfkeysvalueof/pgfplots/samples
pgfmathsetmacroyx/pgfkeysvalueof/pgfplots/samples
pgfmathsetmacroxx/pgfkeysvalueof/pgfplots/samples*3
simplecoordinate(x,0,y)
pgfplotstreamend
pgfusepathstroke
endscope
%
makeatother
begindocument
begintikzpicture
beginaxis[
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)
endaxis
endtikzpicture
enddocument
mesh
@hpekristiansen Yes, you could do that. A slight downside is that you need to give the dummy plots the same color. If you do that,
addlegendimage
will be an even more straightforward choice. There you can add whatever you like. The point here is that you could adjust pgfmathparsefactor*(##3 - rangea)
to create a legend image in which the color changes. This is how tex.stackexchange.com/a/59075/121799 works.– marmot
Sep 14 '18 at 4:35
addlegendimage
pgfmathparsefactor*(##3 - rangea)
@hpekristiansen I completely switched gears and now just use Jake's great answer.
– marmot
Sep 14 '18 at 4:43
Nice answer although I do not understand the low level code.
– hpekristiansen
Sep 14 '18 at 4:52
@hpekristiansen I guess what happened in Jake's answer is that Jake looked up the definition of
pgfplotsplothandlermesh@defaultlegend@img
in pgfplotsmeshplothandler.code.tex
and adjusted it to his needs. There you can find a bunch of simplecoordinate
statements, which define the surface symbol of the ordinary mesh legend
. The perhaps most important thing there is the statement letpgfplots@current@point@meta=pgfmathresult
, which sets the meta (i.e. color) of a point. This gets linked to the third entry of the coordinates, and is how the fading effect is achieved.– marmot
Sep 14 '18 at 4:58
pgfplotsplothandlermesh@defaultlegend@img
pgfplotsmeshplothandler.code.tex
simplecoordinate
mesh legend
letpgfplots@current@point@meta=pgfmathresult
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Just asking for my own personal interest... I suppose that the legend symbol comes from the fact that the plots has
mesh
option!? What if two dummy invisible line plots were added, just to create the legend?– hpekristiansen
Sep 14 '18 at 4:31