von esdd » Do 12. Okt 2017, 10:53
\addplot[fill=myblue]table[y=I]{\data};
nutzt die erste Spalte als x-Wert. Du kannst jetzt entweder für die Ticks
verwenden und damit folgenden Code nutzen:
\documentclass[12pt,a4paper]{report}
\usepackage{pgfplotstable}% lädt u.a. auch pgfplots,tikz, xcolor, ...
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\definecolor{myblue}{HTML}{92dcec}
\usepackage{caption}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\begin{document}
\noindent
\begin{minipage}{\linewidth}
\begin{tikzpicture}
\pgfplotstableread{
Jahr I
{2012} 240
{2013} 256
{2014} 270
{2015} 294
}{\data};
\begin{axis}[
width=\linewidth-45pt,
height=6cm,
scale only axis,
axis lines=left,
x axis line style={|[left]-|[right]},
y axis line style={|[right]-|[left]},
ylabel=Anzahl,
ymin=0,ymax=300,
ytick={50,100,150,200,250,300},
ymajorgrids,
xlabel=Jahr,
xtick={2012,...,2015},
xticklabels from table={\data}{Jahr},
xticklabel style={anchor=east,rotate=45,align=center},
ybar=0pt,
bar width=2cm,
enlarge x limits={abs=2.5cm},
nodes near coords,
legend style={yshift=1cm, column sep=1mm},
legend cell align=left
]
\addplot[fill=myblue]table[y=I]{\data};
\end{axis}
\end{tikzpicture}
\captionof{figure}{Beschreibung}
\end{minipage}
\end{document}
Oder Du verwendest
\addplot[fill=myblue]table[x expr=\coordindex,y=I]{\data};
damit der Koordinatenindex als x-Wert genutzt wird.
\documentclass[12pt,a4paper]{report}
\usepackage{pgfplotstable}% lädt u.a. auch pgfplots,tikz, xcolor, ...
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\definecolor{myblue}{HTML}{92dcec}
\usepackage{caption}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\begin{document}
\noindent
\begin{minipage}{\linewidth}
\begin{tikzpicture}
\pgfplotstableread{
Jahr I
{2012} 240
{2013} 256
{2014} 270
{2015} 294
}{\data};
\begin{axis}[
width=\linewidth-45pt,
height=6cm,
scale only axis,
axis lines=left,
x axis line style={|[left]-|[right]},
y axis line style={|[right]-|[left]},
ylabel=Anzahl,
ymin=0,ymax=300,
ytick={50,100,150,200,250,300},
ymajorgrids,
xlabel=Jahr,
xtick={0,...,4},
xticklabel style={anchor=east,rotate=45,
/pgf/number format/set thousands separator={}
},
ybar=0pt,
bar width=2cm,
enlarge x limits={abs=2.5cm},
nodes near coords,
legend style={yshift=1cm, column sep=1mm},
legend cell align=left
]
\addplot[fill=myblue]table[x expr=\coordindex,y=I]{\data};
\end{axis}
\end{tikzpicture}
\captionof{figure}{Beschreibung}
\end{minipage}
\end{document}
[code]\addplot[fill=myblue]table[y=I]{\data}; [/code]
nutzt die erste Spalte als [tt]x-Wert[/tt]. Du kannst jetzt entweder für die Ticks
[code]xtick={2012,...,2015},[/code]
verwenden und damit folgenden Code nutzen:
[code]
\documentclass[12pt,a4paper]{report}
\usepackage{pgfplotstable}% lädt u.a. auch pgfplots,tikz, xcolor, ...
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\definecolor{myblue}{HTML}{92dcec}
\usepackage{caption}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\begin{document}
\noindent
\begin{minipage}{\linewidth}
\begin{tikzpicture}
\pgfplotstableread{
Jahr I
{2012} 240
{2013} 256
{2014} 270
{2015} 294
}{\data};
\begin{axis}[
width=\linewidth-45pt,
height=6cm,
scale only axis,
axis lines=left,
x axis line style={|[left]-|[right]},
y axis line style={|[right]-|[left]},
ylabel=Anzahl,
ymin=0,ymax=300,
ytick={50,100,150,200,250,300},
ymajorgrids,
xlabel=Jahr,
xtick={2012,...,2015},
xticklabels from table={\data}{Jahr},
xticklabel style={anchor=east,rotate=45,align=center},
ybar=0pt,
bar width=2cm,
enlarge x limits={abs=2.5cm},
nodes near coords,
legend style={yshift=1cm, column sep=1mm},
legend cell align=left
]
\addplot[fill=myblue]table[y=I]{\data};
\end{axis}
\end{tikzpicture}
\captionof{figure}{Beschreibung}
\end{minipage}
\end{document}
[/code]
Oder Du verwendest
[code]\addplot[fill=myblue]table[x expr=\coordindex,y=I]{\data};[/code]
damit der Koordinatenindex als [tt]x[/tt]-Wert genutzt wird.
[code]\documentclass[12pt,a4paper]{report}
\usepackage{pgfplotstable}% lädt u.a. auch pgfplots,tikz, xcolor, ...
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\definecolor{myblue}{HTML}{92dcec}
\usepackage{caption}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\begin{document}
\noindent
\begin{minipage}{\linewidth}
\begin{tikzpicture}
\pgfplotstableread{
Jahr I
{2012} 240
{2013} 256
{2014} 270
{2015} 294
}{\data};
\begin{axis}[
width=\linewidth-45pt,
height=6cm,
scale only axis,
axis lines=left,
x axis line style={|[left]-|[right]},
y axis line style={|[right]-|[left]},
ylabel=Anzahl,
ymin=0,ymax=300,
ytick={50,100,150,200,250,300},
ymajorgrids,
xlabel=Jahr,
xtick={0,...,4},
xticklabel style={anchor=east,rotate=45,
/pgf/number format/set thousands separator={}
},
ybar=0pt,
bar width=2cm,
enlarge x limits={abs=2.5cm},
nodes near coords,
legend style={yshift=1cm, column sep=1mm},
legend cell align=left
]
\addplot[fill=myblue]table[x expr=\coordindex,y=I]{\data};
\end{axis}
\end{tikzpicture}
\captionof{figure}{Beschreibung}
\end{minipage}
\end{document}[/code]