Seite 1 von 1

Bar-Plot mit pgfplots zeigt nicht alle Datenpunkte an

Verfasst: Mo 12. Dez 2022, 15:25
von brisi
Hallo zusammen

Ich habe versucht, einen einfachen Bar-Plot mit pgfplots zu erstellen. Leider schaffe ich es nicht alle Daten im Diagramm abzubilden. Ich habe an dem Parameter
enlargelimits=0.05
versucht zu schrauben, aber es funktioniert nicht.
\documentclass[11pt,a4paper,ngerman]{standalone}
\usepackage[T1]{fontenc}
\usepackage{babel}

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.18}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.05,
legend style={at={(0.5,-0.5)},
anchor=north,legend columns=-1},
ylabel={Score},
symbolic x coords={Moodle,Blackboard,Smartest},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east},
]
\addplot coordinates {(Moodle,45) (Blackboard,60) (Smartest,75)};
\addplot coordinates {(Moodle,75) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,120) (Blackboard,150) (Smartest,150)};
\addplot coordinates {(Moodle,100) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,100) (Blackboard,40) (Smartest,40)};
\legend{Usebility, Privacy, Benefit, Interoperabilität, Kosten}
\end{axis}
\end{tikzpicture}
\end{document}
  • Was muss ich tun, dass alle Balken im Diagrammfeld angezeigt werden?
  • Welche Einstellung erlaubt es mir, die Legende in zwei Zeilen anzuzeigen?
Vielen herzlichen Dank für Eure Hilfe!!

Re: Bar-Plot mit pgfplots zeigt nicht alle Datenpunkte an

Verfasst: Mo 12. Dez 2022, 18:31
von Bartman
Ich habe in meinem Vorschlag nicht nur den Wert der Option enlargelimits, sondern auch die Breite der Zeichnung (width) angepasst.

Die Option, mit der man über die Zahl der Spalten die Anordnung der Einträge in der Legende einstellen kann, wird bereits in der Optionenliste für den Stil der Legende benutzt.
\documentclass[11pt,a4paper,ngerman]{standalone}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{pgfplots}

\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  width=10cm,
  ybar,
  enlargelimits=0.2,
  legend style={
    at={(current bounding box.south)},
    anchor=north,
    yshift=-2mm,
    legend columns=3, 
    cells={anchor=west}
  },
  ylabel={Score},
  symbolic x coords={Moodle,Blackboard,Smartest},
  xtick=data,
  nodes near coords,
  nodes near coords align={vertical},
  nodes near coords style={rotate=90,anchor=west}
]
\addplot coordinates {(Moodle,45) (Blackboard,60) (Smartest,75)};
\addplot coordinates {(Moodle,75) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,120) (Blackboard,150) (Smartest,150)};
\addplot coordinates {(Moodle,100) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,100) (Blackboard,40) (Smartest,40)};
\legend{Usebility, Privacy, Benefit, Interoperabilität, Kosten}
\end{axis}
\end{tikzpicture}
\end{document}

Re: Bar-Plot mit pgfplots zeigt nicht alle Datenpunkte an

Verfasst: Di 13. Dez 2022, 07:53
von brisi
Super, vielen vielen herzlichen Dank für Deine rasche Hilfe!!

Sorry noch eine kleine Rückfrage: Die Grafik sollte in einen zweispaltigen Text, sodass sie schön in die Spalte passt, deshalb die Angabe width=7cm. Würdest Du zum verkleinern \resizebox{\linewidth}{}{} verwenden?
Oder gibt es eine bessere Lösung?
\documentclass[
   ngerman,
   fontsize = 11pt,
   parskip = half,
   headings = small,
]{scrartcl}

% Basispakete
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% Schrift und Farbe
\usepackage[default]{sourcesanspro}
\usepackage[scale = 1]{sourcecodepro}
\usepackage{microtype}


\usepackage{amssymb,amsmath,wasysym}

\usepackage{lipsum}

\title{Titel}
\author{tl}


\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\columnsep0.9cm

\twocolumn[\maketitle]


\lipsum[2-4]

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.05,
legend style={at={(0.5,-0.5)},
anchor=north,legend columns=-1},
ylabel={Score},
symbolic x coords={Moodle,Blackboard,Smartest},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east},
]
\addplot coordinates {(Moodle,45) (Blackboard,60) (Smartest,75)};
\addplot coordinates {(Moodle,75) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,120) (Blackboard,150) (Smartest,150)};
\addplot coordinates {(Moodle,100) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,100) (Blackboard,40) (Smartest,40)};
\legend{Usebility, Privacy, Benefit, Interoperabilität, Kosten}
\end{axis}
\end{tikzpicture}

\end{document}




Re: Bar-Plot mit pgfplots zeigt nicht alle Datenpunkte an

Verfasst: Di 13. Dez 2022, 08:41
von ich meine ja nur
Ich würde die Schriftgröße und die Breite der Balken einstellen und dann ggf. noch mit scale arbeiten:
\documentclass[11pt,a4paper,ngerman,twocolumn]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{pgfplots}

\pgfplotsset{compat=1.18}
\usepackage{showframe}
\usepackage{blindtext}
\begin{document}
\Blindtext[2]
\begin{tikzpicture}
\begin{axis}[
  width=10cm,
  ybar,
  bar width=3mm,
  enlargelimits=0.2,
  legend style={
    at={(current bounding box.south)},
    anchor=north,
    yshift=-2mm,
    legend columns=3, 
    cells={anchor=west}
  },
  ylabel={Score},
  symbolic x coords={Moodle,Blackboard,Smartest},
  xtick=data,
  nodes near coords,
  nodes near coords align={vertical},
  nodes near coords style={rotate=90,anchor=west},
  scale=0.7,
  font=\scriptsize
]
\addplot coordinates {(Moodle,45) (Blackboard,60) (Smartest,75)};
\addplot coordinates {(Moodle,75) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,120) (Blackboard,150) (Smartest,150)};
\addplot coordinates {(Moodle,100) (Blackboard,60) (Smartest,60)};
\addplot coordinates {(Moodle,100) (Blackboard,40) (Smartest,40)};
\legend{Usebility, Privacy, Benefit, Interoperabilität, Kosten}
\end{axis}
\end{tikzpicture}
\Blindtext
\end{document}
\resizebox wäre zwar möglich, dabei wird aber alles skaliert und so beispielsweise die Fonts sehr dünn.