PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Probleme mit einer 'area legend' in pgfplots



Magger
04-12-2012, 19:16
Hallo,

ich habe ein kleines Luxusproblem mit einer Legendenformatierung in pgfplots, siehe dazu folgenden Minimalbeispiel:


\documentclass{scrartcl}

\usepackage{pgfplots}
\usetikzlibrary{patterns}

\pgfplotsset{compat=newest}
\pgfplotsset{cycle list name=color list}
\pgfplotsset{every axis plot/.append style={line width=1pt}}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=center,
xmajorgrids=false,
ymajorgrids=false,
legend style={draw=none},
xlabel={Zeit},
ylabel={Amplitude},
xmin=0,xmax=3.5,
ymin=0,ymax=2,
width=0.9\textwidth,
height=0.45\textwidth,
xtick={0.5,1.5,2.5},
xticklabels={Offen,Schaltvorgang,Geschlossen},
xtick style={draw=none},
ytick=\empty,
legend pos=north east,
]
\addplot+[
area legend,
pattern=north west lines,
pattern color=brown,
domain=1:2,
samples=101,
draw=none,
]{4*(x-1)*(2-x)} \closedcycle;
\addlegendentry{Verlustenergie im Schalter}
\addplot coordinates {
(0,0)
(1,0)
(2,1)
(3,1)
};
\addlegendentry{Strom durch den Schalter}
\addplot+[dashed] coordinates {
(0,1)
(1,1)
(2,0)
(3,0)
};
\addlegendentry{Spannung \"{u}ber dem Schalter}
\addplot+[
dotted,green,
domain=0:1,
samples=2,
]{0};
\pgfplotsset{cycle list shift=-1};
\addplot+[
dotted,green,
domain=1:2,
samples=101,
]{4*(x-1)*(2-x)};
\pgfplotsset{cycle list shift=-2};
\addplot+[
dotted,green,
domain=2:3,
samples=2,
]{0};
\addlegendentry{Verlustleistung im Schalter}
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

Ich möchte den ersten Plot mit der Fläche nur schraffieren und nicht umranden, deshalb habe ich draw=none gesetzt.

Trotzdem wird die schraffierte Fläche in der Legende umrandet. Wie kann man das abstellen?

Viele Grüße, Mathias

esdd
04-12-2012, 20:29
Hallo,

verwende draw opacity=0 statt draw=none.

Du kannst dir dafür auch einen neuen legend style mit \fill statt \draw definieren:

\pgfplotsset{my area legend/.style={
legend image code/.code={\fill[#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);}
}
}

Gruß
Elke

Magger
04-12-2012, 21:07
Vielen Dank.