Tikz Legendeneintrag

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: Tikz Legendeneintrag

Re: Tikz Legendeneintrag

von Stefan Kottwitz » Di 11. Jun 2024, 13:01

basti-fantasti-48 hat geschrieben:
Di 11. Jun 2024, 12:45
ja habe es auskommentiert aber trdm bleibt es bei dem fehlerbild
da Du es nicht erwähnt hast, hast Du vllt. die Option forget plot vergessen?

Stefan

Re: Tikz Legendeneintrag

von basti-fantasti-48 » Di 11. Jun 2024, 12:45

ja habe es auskommentiert aber trdm bleibt es bei dem fehlerbild

Re: Tikz Legendeneintrag

von Stefan Kottwitz » Di 11. Jun 2024, 12:43

Dann lösche \addlegendentry{steig}; wenn Du das nicht brauchst, und sag das auch dem \addplot-Befehl mit der forget plot Option:
\addplot[dashed,domain=0:1,line width=1.5pt, forget plot] {x};
Stefan

Re: Tikz Legendeneintrag

von basti-fantasti-48 » Di 11. Jun 2024, 12:32

diese gestrichelte schwarze Linie im Diagramm soll eben nicht in die Legende und das macht die Probleme glaube ich

Re: Tikz Legendeneintrag

von Stefan Kottwitz » Di 11. Jun 2024, 12:22

Doch, hier habe ich die beiden Zeilen eingefügt, klicke mal auf LaTeX-Ausgabe:
\documentclass[
11pt,					% Schriftgröße
paper=a4,
DIV=13,				% Seitenlayout (Satzspiegel)
parskip=half,			% Abstand zwischen Absätzen
%twoside,				% Doppelseitig
%openright,			% neues Kapitel rechts
%  cleardoublepage,
bibtotoc,				% Literaturverzeichis in Inhaltsverzeichnis
headsepline,			% Kopfzeilentrennlinie
headings,	
%  draft,				% Korrekturfassung
]{scrreprt}		% scrartcl	

% Eingabecodierung
\usepackage[utf8]{inputenc}

% Schriftcodierung
\usepackage[T1]{fontenc}

% Sprachraum
\usepackage[ngerman]{babel}

% Blindtext
\usepackage{blindtext}

% Schrifteinstellungen
\usepackage{lmodern} 		% Vektorschrift
\renewcommand{\familydefault}{\sfdefault} % Serifenlose Schrift
\usepackage{sansmath}  	% Mathe-Schrift ohne Serifen
\sansmath 							% aktiviert serifenlose Matheschrift
\usepackage{microtype}	% harmonische Typenverteilung
%\usepackage{hyperref}

% Literatur einbinden
\usepackage{csquotes}	% Steuerung der Anführungszeichen
\usepackage[
backend=biber,			% Sortier-Compiler
style=numeric-comp,	% Zitationsstil
block=ragged,
]{biblatex}

\addbibresource{ref/Bibliothek.bib}

\usepackage{booktabs}

% Mathemodus
\usepackage{amsmath,amssymb}

% Trennung
\hyphenation{Crash-zo-ne}

% Bilder einbinden
\usepackage{graphicx}
\graphicspath{{bilder/}}
\usepackage{svg}




\usepackage{pgfkeys}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{startstop} = [rectangle, rounded corners, 
minimum width=3cm, 
minimum height=1cm,
text centered, 
draw=black, 
fill=red!30]

\tikzstyle{io} = [trapezium, 
trapezium stretches=true, % A later addition
trapezium left angle=70, 
trapezium right angle=110, 
minimum width=3cm, 
minimum height=1cm, text centered, 
draw=black, fill=blue!30]

\tikzstyle{process} = [rectangle, 
minimum width=3cm, 
minimum height=1cm, 
text centered, 
text width=3cm, 
draw=black, 
fill=orange!30]

\tikzstyle{decision} = [diamond, 
minimum width=3cm, 
minimum height=1cm, 
text centered, 
draw=black, 
fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta,positioning,calc}

%für lange Tabelle
\usepackage{longtable} 
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[export]{adjustbox}
% für tikz
\pgfplotsset{select coords between index/.style 2 args={
		x filter/.code={
			\ifnum\coordindex<#1\def\pgfmathresult{}\fi
			\ifnum\coordindex>#2\def\pgfmathresult{}\fi
		}
}}
\usepackage{subcaption}
\usepackage{pdfpages}
\usepackage{acronym}%abkürzung
\usetikzlibrary{arrows, decorations.markings}
\makeatletter
\tikzset{
	nomorepostaction/.code=\makeatletter\let\tikz@postactions\pgfutil@empty,
	my axis/.style={
		postaction={
			decoration={
				markings,
				mark=at position 1 with {
					\arrow[ultra thick]{latex}
				}
			},
			decorate,
			nomorepostaction
		},
		thin,
		-, % switch off other arrow tips
		every path/.append style=my axis % this is necessary
		%so it works both with "axis lines=left" and "axis lines=center"
	}
}
\makeatother




\renewcommand*{\chapterheadstartvskip}{\vspace*{-1\baselineskip}}% Abstand einstellen
\renewcommand*\chapterheadendvskip{%
	\vspace*{1\baselineskip plus -1\baselineskip minus .167\baselineskip}}


\begin{document}
	\begin{figure}[htpb]
	\begin{subfigure}{0.55\textwidth}
		\begin{tikzpicture} 
			
			\begin{axis}[
				%xtick=\empty,
				xlabel={$x$},
				ylabel={$y$},
				ymax=1.1,
				%title={Plot der Funktion $y = x^2$},
				grid=major,
				domain=0:5,
				axis line style={my axis},
				samples=100,
				axis lines=left,
				xticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi},
				legend pos=south east, 
				]
				
				\addplot[red,line width=1.5pt] {1-e^-x};
				\addlegendentry{$x$};
				%	\addplot[blue, dashed]{1};
				\addplot[blue,domain=0:1.25,line width=1.5pt]{0.8*x};
				\addlegendentry{$y$};
				\addplot[gray, dashed,line width=1.5pt]{1};
			\end{axis}
			
			
		\end{tikzpicture}
		\caption{bild a}
		\label{a}
	\end{subfigure}%
	\begin{subfigure}{0.5\textwidth}
		\begin{tikzpicture}
			\begin{axis}[
				xlabel={$t$},
				%ylabel={$xy$},
				ymax=1.1,
				grid=major,
				domain=0:5,
				samples=100,
				axis lines=left, 
				axis line style={my axis},
				xticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi},
				legend pos=south east,
				]
				
				\addplot[red,domain=0:1,line width=1.5pt] {x^2};
				\addlegendentry{$x$}
				\addplot[dashed,domain=0:1,line width=1.5pt] {x};
				
				\draw[green] (0.2,0.2) -- (0.2,0.4) -- (0.4,0.4);
    \node at (0.2,0.5) [green] {steig};
    \addlegendentry{steig};
    \addlegendimage{line legend,dashed,green};
    \addlegendentry{Größe};
			\end{axis}
		\end{tikzpicture}
		\caption{bild b}
		\label{b}
	\end{subfigure}
	\caption{Veranschaulichung}
\end{figure}
\end{document}
Deine Zeile mit \addlegendimage habe ich entfernt, damit nichts doppelt passiert.

Stefan

Re: Tikz Legendeneintrag

von basti-fantasti-48 » Di 11. Jun 2024, 12:08

ja funktioniert aber nicht (auch nicht mit dem was du geschickt hast) ?

Re: Tikz Legendeneintrag

von Stefan Kottwitz » Di 11. Jun 2024, 11:01

So ähnlich hast Du ja schon angefangen:
\addlegendimage{line legend,dashed,green};
\addlegendentry{Größe};
Stefan

Tikz Legendeneintrag

von basti-fantasti-48 » Di 11. Jun 2024, 10:39

Hallo ich habe in grün etwas ins diagramm eingezeichnet (in diesem fall steigung). Ich möchte jetzt in der Legende einen grünen strich und dann die größe(steig) (bei mir ist es eine gestrichelte Linie und dann die Größe)

Die gestrichelte Linien in meinem diagramm soll bleiben aber nicht in die legende
\documentclass[
11pt,					% Schriftgröße
paper=a4,
DIV=13,				% Seitenlayout (Satzspiegel)
parskip=half,			% Abstand zwischen Absätzen
%twoside,				% Doppelseitig
%openright,			% neues Kapitel rechts
%  cleardoublepage,
bibtotoc,				% Literaturverzeichis in Inhaltsverzeichnis
headsepline,			% Kopfzeilentrennlinie
headings,	
%  draft,				% Korrekturfassung
]{scrreprt}		% scrartcl	

% Eingabecodierung
\usepackage[utf8]{inputenc}

% Schriftcodierung
\usepackage[T1]{fontenc}

% Sprachraum
\usepackage[ngerman]{babel}

% Blindtext
\usepackage{blindtext}

% Schrifteinstellungen
\usepackage{lmodern} 		% Vektorschrift
\renewcommand{\familydefault}{\sfdefault} % Serifenlose Schrift
\usepackage{sansmath}  	% Mathe-Schrift ohne Serifen
\sansmath 							% aktiviert serifenlose Matheschrift
\usepackage{microtype}	% harmonische Typenverteilung
%\usepackage{hyperref}

% Literatur einbinden
\usepackage{csquotes}	% Steuerung der Anführungszeichen
\usepackage[
backend=biber,			% Sortier-Compiler
style=numeric-comp,	% Zitationsstil
block=ragged,
]{biblatex}

\addbibresource{ref/Bibliothek.bib}

\usepackage{booktabs}

% Mathemodus
\usepackage{amsmath,amssymb}

% Trennung
\hyphenation{Crash-zo-ne}

% Bilder einbinden
\usepackage{graphicx}
\graphicspath{{bilder/}}
\usepackage{svg}




\usepackage{pgfkeys}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{startstop} = [rectangle, rounded corners, 
minimum width=3cm, 
minimum height=1cm,
text centered, 
draw=black, 
fill=red!30]

\tikzstyle{io} = [trapezium, 
trapezium stretches=true, % A later addition
trapezium left angle=70, 
trapezium right angle=110, 
minimum width=3cm, 
minimum height=1cm, text centered, 
draw=black, fill=blue!30]

\tikzstyle{process} = [rectangle, 
minimum width=3cm, 
minimum height=1cm, 
text centered, 
text width=3cm, 
draw=black, 
fill=orange!30]

\tikzstyle{decision} = [diamond, 
minimum width=3cm, 
minimum height=1cm, 
text centered, 
draw=black, 
fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta,positioning,calc}

%für lange Tabelle
\usepackage{longtable} 
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[export]{adjustbox}
% für tikz
\pgfplotsset{select coords between index/.style 2 args={
		x filter/.code={
			\ifnum\coordindex<#1\def\pgfmathresult{}\fi
			\ifnum\coordindex>#2\def\pgfmathresult{}\fi
		}
}}
\usepackage{subcaption}
\usepackage{pdfpages}
\usepackage{acronym}%abkürzung
\usetikzlibrary{arrows, decorations.markings}
\makeatletter
\tikzset{
	nomorepostaction/.code=\makeatletter\let\tikz@postactions\pgfutil@empty,
	my axis/.style={
		postaction={
			decoration={
				markings,
				mark=at position 1 with {
					\arrow[ultra thick]{latex}
				}
			},
			decorate,
			nomorepostaction
		},
		thin,
		-, % switch off other arrow tips
		every path/.append style=my axis % this is necessary
		%so it works both with "axis lines=left" and "axis lines=center"
	}
}
\makeatother




\renewcommand*{\chapterheadstartvskip}{\vspace*{-1\baselineskip}}% Abstand einstellen
\renewcommand*\chapterheadendvskip{%
	\vspace*{1\baselineskip plus -1\baselineskip minus .167\baselineskip}}


\begin{document}
	\begin{figure}[htpb]
	\begin{subfigure}{0.55\textwidth}
		\begin{tikzpicture} 
			
			\begin{axis}[
				%xtick=\empty,
				xlabel={$x$},
				ylabel={$y$},
				ymax=1.1,
				%title={Plot der Funktion $y = x^2$},
				grid=major,
				domain=0:5,
				axis line style={my axis},
				samples=100,
				axis lines=left,
				xticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi},
				legend pos=south east, 
				]
				
				\addplot[red,line width=1.5pt] {1-e^-x};
				\addlegendentry{$x$};
				%	\addplot[blue, dashed]{1};
				\addplot[blue,domain=0:1.25,line width=1.5pt]{0.8*x};
				\addlegendentry{$y$};
				\addplot[gray, dashed,line width=1.5pt]{1};
			\end{axis}
			
			
		\end{tikzpicture}
		\caption{bild a}
		\label{a}
	\end{subfigure}%
	\begin{subfigure}{0.5\textwidth}
		\begin{tikzpicture}
			\begin{axis}[
				xlabel={$t$},
				%ylabel={$xy$},
				ymax=1.1,
				grid=major,
				domain=0:5,
				samples=100,
				axis lines=left, 
				axis line style={my axis},
				xticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi},
				legend pos=south east,
				]
				
				\addplot[red,domain=0:1,line width=1.5pt] {x^2};
				\addlegendentry{$x$}
				\addplot[dashed,domain=0:1,line width=1.5pt] {x};
				
				\draw[green] (0.2,0.2) -- (0.2,0.4) -- (0.4,0.4);
    \node at (0.2,0.5) [green] {steig};
    
    % Unsichtbarer grüner Plot für die Legende
       \addlegendimage{green, line width=1.5pt};
    \addlegendentry{steig};
			\end{axis}
		\end{tikzpicture}
		\caption{bild b}
		\label{b}
	\end{subfigure}
	\caption{Veranschaulichung}
\end{figure}
\end{document}

Nach oben