Graph geht zu hoch (y-achse) Thema ist als GELÖST markiert

Tabellen und Grafiken erstellen und anordnen


basti-fantasti-48
Forum-Century
Forum-Century
Beiträge: 214
Registriert: So 4. Apr 2021, 14:27

Graph geht zu hoch (y-achse)

Beitrag von basti-fantasti-48 »

 \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}




\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"
	}
}
\begin{document}


\begin{figure}[ht] % links nicht bis 5 hoch
	\begin{tikzpicture}[baseline]
		\pgfplotstableread{
			x y   
			
			1 5
			5 4.7
			10 4.4
			15 4.1
			20 3.8
			25 3.72
			30 3.7
			35 3.7
			40 3.7
			45 3.7
			50 3.7
			55 3.72
			60 3.75
			70 3.98
			75 4.13
			80 4.33
			85 4.53
			90 4.73	
			
		}\mytable
		\begin{axis}[
			xtick=\empty,ytick=\empty,
			axis lines=left,
			xlabel={x},
			ylabel={y},
			axis line style={my axis},
			xmin=0,
			xmax=100,
			ymin=3.6,
			width=\linewidth, %Bildbreite
			height=7cm,	%Bildhöhe
			]
			\draw[<->] (axis cs:1,4.7) -- node[above] {Bereich 1} (axis cs:23,4.7);
			\draw[<->] (axis cs:25,4.7) -- node[above] {Bereich 2} (axis cs:58,4.7);
			\draw[<->] (axis cs:60,4.7) -- node[above] {Bereich 3} (axis cs:85,4.7);
			\draw[dashed] (axis cs:24,1)--(axis cs:24,5);
			\draw[dashed] (axis cs:59,1)--(axis cs:59,5);
			\addplot  +[
			smooth,
			no marks,
			line join=round,line width=1.5pt,
			] 
			table [x=x,y=y] {\mytable};
		\end{axis}
		
	\end{tikzpicture}

\end{figure} 
\end{document}
hallo ich möchte das der Graph links etwas eher aufhört. (bei 4,8) mit domain geht es nicht. Kann mir da jemand die entsprechende Änderung in meinem mitgeliefertem code einbauen?

Benutzeravatar
Stefan Kottwitz
Admin
Admin
Beiträge: 2759
Registriert: Di 8. Jul 2008, 00:39
Kontaktdaten:

Re: Graph geht zu hoch (y-achse)

Beitrag von Stefan Kottwitz »

Das geht mit restrict y to domain = 0:4.8. Dazu ymax etwas größer setzen, damit das Koordinatensystem selber nicht kleiner wird. Zeilen 168-169.
\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}




\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"
	}
}
\begin{document}


\begin{figure}[ht] % links nicht bis 5 hoch
	\begin{tikzpicture}[baseline]
		\pgfplotstableread{
			x y   
			
			1 5
			5 4.7
			10 4.4
			15 4.1
			20 3.8
			25 3.72
			30 3.7
			35 3.7
			40 3.7
			45 3.7
			50 3.7
			55 3.72
			60 3.75
			70 3.98
			75 4.13
			80 4.33
			85 4.53
			90 4.73	
			
		}\mytable
		\begin{axis}[
			xtick=\empty,ytick=\empty,
			axis lines=left,
			xlabel={x},
			ylabel={y},
			axis line style={my axis},
			xmin=0,
			xmax=100,
			ymin=3.6,
			width=\linewidth, %Bildbreite
			height=7cm,	%Bildhöhe
			restrict y to domain = 0:4.8,
			ymax=5,
			]
			\draw[<->] (axis cs:1,4.7) -- node[above] {Bereich 1} (axis cs:23,4.7);
			\draw[<->] (axis cs:25,4.7) -- node[above] {Bereich 2} (axis cs:58,4.7);
			\draw[<->] (axis cs:60,4.7) -- node[above] {Bereich 3} (axis cs:85,4.7);
			\draw[dashed] (axis cs:24,1)--(axis cs:24,5);
			\draw[dashed] (axis cs:59,1)--(axis cs:59,5);
			\addplot  +[
			smooth,
			no marks,
			line join=round,line width=1.5pt,
			] 
			table [x=x,y=y] {\mytable};
		\end{axis}
		
	\end{tikzpicture}

\end{figure} 
\end{document}
Stefan

basti-fantasti-48
Forum-Century
Forum-Century
Beiträge: 214
Registriert: So 4. Apr 2021, 14:27

Re: Graph geht zu hoch (y-achse)

Beitrag von basti-fantasti-48 »

danke aber rechts gehts ja trotzdem darüber hinaus

Benutzeravatar
Stefan Kottwitz
Admin
Admin
Beiträge: 2759
Registriert: Di 8. Jul 2008, 00:39
Kontaktdaten:

Re: Graph geht zu hoch (y-achse)

Beitrag von Stefan Kottwitz »

Rechts geht es bis auf 4.73 was über der Linie bei 4.7 ist, es ist aber noch unter der gewünschten Begrenzung auf 4.8. Dann setze das Limit eben auf 4.7 statt 4.8. Dann fehlen Dir natürlich die Werte darüber.

Stefan

basti-fantasti-48
Forum-Century
Forum-Century
Beiträge: 214
Registriert: So 4. Apr 2021, 14:27

Re: Graph geht zu hoch (y-achse)

Beitrag von basti-fantasti-48 »

welche 4.7 Linie? es ist doch auf 4.8 begrenzt. was muss ich tun?

Benutzeravatar
Stefan Kottwitz
Admin
Admin
Beiträge: 2759
Registriert: Di 8. Jul 2008, 00:39
Kontaktdaten:

Re: Graph geht zu hoch (y-achse)

Beitrag von Stefan Kottwitz »

Du hast diese Linien hier auf 4.7 Höhe:
\draw[<->] (axis cs:1, 4.7) -- node[above] {Bereich 1} (axis cs:23,4.7);
\draw[<->] (axis cs:25,4.7) -- node[above] {Bereich 2} (axis cs:58,4.7);
\draw[<->] (axis cs:60,4.7) -- node[above] {Bereich 3} (axis cs:85,4.7);
Daher ist die Kurve, wenn Du sie auf 4.8 begrenzt, höher.

Stefan

basti-fantasti-48
Forum-Century
Forum-Century
Beiträge: 214
Registriert: So 4. Apr 2021, 14:27

Re: Graph geht zu hoch (y-achse)

Beitrag von basti-fantasti-48 »

Kapier ich nicht die Linien kann ich doch auch mitten rein schieben in die Grafik. Warum ist die Kurve dann höher. Ich begrenze auf 4.8 und es geht rechts darüber hinaus. Was sollen Linien damit zu tun haben

Benutzeravatar
Stefan Kottwitz
Admin
Admin
Beiträge: 2759
Registriert: Di 8. Jul 2008, 00:39
Kontaktdaten:

Re: Graph geht zu hoch (y-achse)

Beitrag von Stefan Kottwitz »

basti-fantasti-48 hat geschrieben:
Di 4. Jun 2024, 08:32
Kapier ich nicht die Linien kann ich doch auch mitten rein schieben in die Grafik.
Kannst Du.
basti-fantasti-48 hat geschrieben:
Di 4. Jun 2024, 08:32
Warum ist die Kurve dann höher.
Weil Du links einen Wert von 5 hast und rechts einen Wert von 4.73, was höher ist als die bei 4.7 gezeichnete Linie.
basti-fantasti-48 hat geschrieben:
Di 4. Jun 2024, 08:32
Ich begrenze auf 4.8 und es geht rechts darüber hinaus.
Es geht nicht über 4.8 hinaus, sondern es geht über die Linie bei 4.7 hinaus, und Du begrenzt auf 4.8.
basti-fantasti-48 hat geschrieben:
Di 4. Jun 2024, 08:32
Was sollen Linien damit zu tun haben
An sich nicht, Du bringt es nur damit zusammen: Du begrenzt auf 4.8 und wunderst Dich, warum es eine beliebige Linie bei 4.7 überschreitet, das ist doch normal. Begrenze auf 4.7 oder zeichne die Linie bei 4.8 wenn es Dir darum geht, die Linie nicht zu überschreiten.

Stefan

basti-fantasti-48
Forum-Century
Forum-Century
Beiträge: 214
Registriert: So 4. Apr 2021, 14:27

Re: Graph geht zu hoch (y-achse)

Beitrag von basti-fantasti-48 »

Ok danke habe es jetzt glaube ich soweit passend.

Mir gings nicht um die Linie sondern um den blauen Graphen. Ich habe rechts den Wert 4.73 und verstehe nicht wieso der höher ist als links wo ich auf 4.8 begrente, da 4.8>4.73

Benutzeravatar
Stefan Kottwitz
Admin
Admin
Beiträge: 2759
Registriert: Di 8. Jul 2008, 00:39
Kontaktdaten:

Re: Graph geht zu hoch (y-achse)

Beitrag von Stefan Kottwitz »

Links sieht es begrenzt aus auf 4.7, weil der Wert in der Tabelle 4.7 ist. Es geht nicht bis 4.8, weil der erste Wert von 5 verworfen wird. Sieht unpraktisch aus, weil es nicht bei 4.8 "abgeschnitten" wird, sondern der Punkt mit Wert 5 verworfen wird, so beginnt es erst beim 2. Wert mit 4.7.

Stefan

Antworten