pgfplots skalieren

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: pgfplots skalieren

Re: pgfplots skalieren

von Diago » Mi 20. Jan 2021, 08:19

Vielen Dank werde ich gleich mal ausprobieren!

Re: pgfplots skalieren

von Bartman » Di 19. Jan 2021, 16:42

Der Vollständigkeit halber gäbe es da noch weitere Möglichkeiten zur Anpassung der Größe.

Das Einfügen der Werte an den jeweiligen Achsen lässt sich noch etwas optimieren:

\begin{filecontents}{\jobname.csv}
Wert;Spalte2;Spalte3;Spalte4;Spalte5;Rate
0;0-0.25;18;8;26;69%
0.25;0.25-0.5;31;9;40;78%
0.75;0.75-1;26;8;34;76%
1;01.01.2025;202;74;276;73%
1.25;1.25-1.5;406;136;542;75%
1.5;1.5-1.75;229;62;291;79%
1.75;1.75-2;319;111;430;74%
2;02.02.2025;48;21;69;70%
2.25;2.25-2.5;43;12;55;78%
4.75;4.75-5;30;11;41;73%
5;05.05.2025;260;66;326;80%
9;09.09.2025;13;5;18;72%
10.25;10.25-10.5;13;4;17;76%
12.25;12.25-12.5;8;5;13;62%
12.5;12.5-12.75;71;107;178;40%
12.75;12.75-13;83;81;164;51%
13;13-13.25;183;74;257;71%
13.25;13.25-13.5;106;83;189;56%
13.5;13.5-13.75;9;4;13;69%
15;15-15.25;24;45;69;35%
15.25;15.25-15.5;31;50;81;38%
15.5;15.5-15.75;66;34;100;66%
15.75;15.75-16;29;16;45;64%
16;16-16.25;9;7;16;56%
16.25;16.25-16.5;11;4;15;73%
16.5;16.5-16.75;3;8;11;27%
16.75;16.75-17;2;9;11;18%
17;17-17.25;16;21;37;43%
17.25;17.25-17.5;6;15;21;29%
18.25;18.25-18.5;1;13;14;7%
20;>20;7;23;30;23%	
\end{filecontents}

\documentclass{scrbook}
\usepackage{pgfplots}% lädt tikz
\usepackage{showframe}
\usepgfplotslibrary{units}

\pgfplotsset{compat=1.17}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[scale=.97]
        \begin{axis}[
            width=\linewidth, % Scale the plot to \linewidth
            grid=major, 
            grid style={dashed,gray!30},
            xlabel=Wert, % Set the labels
            ylabel=Rate,
            x unit=wt.\%, % Set the respective units
            %	y unit=\%,
            xmin=0, xmax=22, ymin=0, ymax=100,
            yticklabel={\pgfmathprintnumber{\tick}\,\%},
            xtick={0,...,22}
        ]
        \addplot [only marks, mark=*, forget plot] table [
            x=Wert,
            y=Rate,
            col sep=semicolon
        ]{\jobname.csv};
        \addplot [no marks, red, domain=0:22, samples=100] 
            {(0.7207+0.02485*x-0.002656*x^2)*100}
        ;
        \end{axis}
    \end{tikzpicture}
    \caption{Minimalbeispiel}
    \label{dia:minimalbeispiel}
\end{figure}
\end{document}

Re: pgfplots skalieren

von gast » Di 19. Jan 2021, 16:03

Man könnte beispielsweise TikZ' Option scale verwenden. Näheres zu der Option und ihren Auswirkungen ist der Anleitung zu entnehmen.

\begin{filecontents}{\jobname.csv}
Wert;Spalte2;Spalte3;Spalte4;Spalte5;Rate
0;0-0.25;18;8;26;69%
0.25;0.25-0.5;31;9;40;78%
0.75;0.75-1;26;8;34;76%
1;01.01.2025;202;74;276;73%
1.25;1.25-1.5;406;136;542;75%
1.5;1.5-1.75;229;62;291;79%
1.75;1.75-2;319;111;430;74%
2;02.02.2025;48;21;69;70%
2.25;2.25-2.5;43;12;55;78%
4.75;4.75-5;30;11;41;73%
5;05.05.2025;260;66;326;80%
9;09.09.2025;13;5;18;72%
10.25;10.25-10.5;13;4;17;76%
12.25;12.25-12.5;8;5;13;62%
12.5;12.5-12.75;71;107;178;40%
12.75;12.75-13;83;81;164;51%
13;13-13.25;183;74;257;71%
13.25;13.25-13.5;106;83;189;56%
13.5;13.5-13.75;9;4;13;69%
15;15-15.25;24;45;69;35%
15.25;15.25-15.5;31;50;81;38%
15.5;15.5-15.75;66;34;100;66%
15.75;15.75-16;29;16;45;64%
16;16-16.25;9;7;16;56%
16.25;16.25-16.5;11;4;15;73%
16.5;16.5-16.75;3;8;11;27%
16.75;16.75-17;2;9;11;18%
17;17-17.25;16;21;37;43%
17.25;17.25-17.5;6;15;21;29%
18.25;18.25-18.5;1;13;14;7%
20;>20;7;23;30;23%	
\end{filecontents}



\documentclass{scrbook} %Dokumentenklasse einstellen! Empfohlen entweder scrbook oder scrrpt

\usepackage[margin=10pt,font=small,labelfont=bf,format=plain,indention=.2cm]{caption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units}


\begin{document}


\begin{figure}[h!]
\centering
		\begin{tikzpicture}[scale=0.8]
			\begin{axis}[
				width=\linewidth, % Scale the plot to \linewidth
				grid=major, 
				grid style={dashed,gray!30},
				xlabel=Wert, % Set the labels
				ylabel=Rate,
				x unit=wt.\%, % Set the respective units
				%	y unit=\%,
				legend style={at={(0.8,0.8)},anchor=north},
				x tick label style={rotate=0,
					anchor=north},
				xmin=0,	xmax=22, ymin=0, ymax=100,
				yticklabels={0\,\%,0\,\%,10\,\%,20\,\%,30\,\%,40\,\%,50\,\%,60\,\%,70\,\%,80\,\%,90\,\%,100\,\%},
				xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22},	]
				
			\addplot [only marks, mark=*, forget plot]
			% add a plot from table; you select the columns by using the actual name in
			% the .csv file (on top)
			table[x=Wert,
			y=Rate,
			col sep=semicolon]
			{\jobname.csv}; 
			
		
			\addplot [no marks, red, domain=0:22, samples=100] {(0.7207+0.02485*x-0.002656*x^2)*100};			
			
			\end{axis}
	\end{tikzpicture}
	\caption{Minimalbeispiel}
	\label{dia:minimalbeispiel}
\end{figure}

\end{document}

Beachte unbedingt auch: Wie zentriere ich eine Abbildung oder Tabelle richtig?

pgfplots skalieren

von Diago » Di 19. Jan 2021, 14:43

Hallo zusammen,

ich habe mir Diagramme mit Pgfplots erstellt - sehen auch soweit super aus. Allerdings sind die mir in Summe ein Stückchen zu groß und daher wirkt die Seite etwas überfrachtet.

Welche Möglichkeiten habe ich die Diagramme entsprechend zu skalieren? Ich habe es versucht mit
width=0.8\linewidth das klappt zwar auch irgendwie (also die Grafik ist dann kleiner), allerdings verschiebt das auch meine Werte - sprich bei der y Achse ist dann nicht mehr 100% max sondern 50%, faszinierender Weise bleiben die Punkte aber an den selben stellen. Will heißen das Diagram wird einfach falsch.

hier ein Minimalbeispiel:

\begin{filecontents}{minimalbeispiel.csv}
Wert;Spalte2;Spalte3;Spalte4;Spalte5;Rate
0;0-0.25;18;8;26;69%
0.25;0.25-0.5;31;9;40;78%
0.75;0.75-1;26;8;34;76%
1;01.01.2025;202;74;276;73%
1.25;1.25-1.5;406;136;542;75%
1.5;1.5-1.75;229;62;291;79%
1.75;1.75-2;319;111;430;74%
2;02.02.2025;48;21;69;70%
2.25;2.25-2.5;43;12;55;78%
4.75;4.75-5;30;11;41;73%
5;05.05.2025;260;66;326;80%
9;09.09.2025;13;5;18;72%
10.25;10.25-10.5;13;4;17;76%
12.25;12.25-12.5;8;5;13;62%
12.5;12.5-12.75;71;107;178;40%
12.75;12.75-13;83;81;164;51%
13;13-13.25;183;74;257;71%
13.25;13.25-13.5;106;83;189;56%
13.5;13.5-13.75;9;4;13;69%
15;15-15.25;24;45;69;35%
15.25;15.25-15.5;31;50;81;38%
15.5;15.5-15.75;66;34;100;66%
15.75;15.75-16;29;16;45;64%
16;16-16.25;9;7;16;56%
16.25;16.25-16.5;11;4;15;73%
16.5;16.5-16.75;3;8;11;27%
16.75;16.75-17;2;9;11;18%
17;17-17.25;16;21;37;43%
17.25;17.25-17.5;6;15;21;29%
18.25;18.25-18.5;1;13;14;7%
20;>20;7;23;30;23%	
\end{filecontents}



\documentclass{scrbook} %Dokumentenklasse einstellen! Empfohlen entweder scrbook oder scrrpt

\usepackage[margin=10pt,font=small,labelfont=bf,format=plain,indention=.2cm]{caption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units}


\begin{document}


\begin{figure}[h!]
		\begin{center}
		\begin{tikzpicture}
			\begin{axis}[
				width=\linewidth, % Scale the plot to \linewidth
				grid=major, 
				grid style={dashed,gray!30},
				xlabel=Wert, % Set the labels
				ylabel=Rate,
				x unit=wt.\%, % Set the respective units
				%	y unit=\%,
				legend style={at={(0.8,0.8)},anchor=north},
				x tick label style={rotate=0,
					anchor=north},
				xmin=0,	xmax=22, ymin=0, ymax=100,
				yticklabels={0\,\%,0\,\%,10\,\%,20\,\%,30\,\%,40\,\%,50\,\%,60\,\%,70\,\%,80\,\%,90\,\%,100\,\%},
				xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22},	]
				
			\addplot [only marks, mark=*, forget plot]
			% add a plot from table; you select the columns by using the actual name in
			% the .csv file (on top)
			table[x=Wert,
			y=Rate,
			col sep=semicolon]
			{minimalbeispiel.csv}; 
			
		
			\addplot [no marks, red, domain=0:22, samples=100] {(0.7207+0.02485*x-0.002656*x^2)*100};			
			
			\end{axis}
	\end{tikzpicture}
	\caption{Minimalbeispiel}
	\label{dia:minimalbeispiel}
\end{center}
\end{figure}

\end{document}

Zum Testen meines Fehlers einfach width=\linewidth, durch width=0.8\linewidth, ersetzen.

Wie kriege ich das sauber hin?


Nach oben