ich möchte ein Diagramm mit Latex darstellen, dass veschiedene Balken mit unterschiedlichen breiten darstellt. Leider wird jeder Balken immer mit der letzten benutzten Breite verwendet.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
% Predefined lists for wavelength data and electron data
\def\wavelengths{{800,850,900,950,1000,1050,1100,1150,1200,1250,1300,1350,1400,1450,1500,1550,1600}}
\def\electrondata{{5000,5500,6000,6500,7000,7500,8000,8500,9000,9500,10000,10500,11000,11500,12000,12500,13000}}
% Define the list of bar widths
\def\cwlaccuracies{{10,20,30,20,15,7.5,7.5,10,15,6,6,15,10,15}}
% Get the number of rows in the wavelength data
\pgfmathsetmacro{\numrows}{14} % Number of rows is known beforehand
% Define the dark current value
\pgfmathsetmacro{\darkcurrent}{1000} % Example value
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel={Wavelength (nm)},
ylabel={Electrons},
legend style={at={(0.5,-0.15)},anchor=north},
width=0.8\textwidth, % Adjust width as needed
height=8cm, % Adjust height as needed
ymin=0, % Default minimum value for the y-axis
ymax=50000, % Default maximum value for the y-axis
xmin=700, % Default minimum value for the x-axis
xmax=1600, % Default maximum value for the x-axis
]
% Plot the green bars representing electrons
\pgfplotsinvokeforeach{0,...,\numrows-1}{
\pgfmathsetmacro{\currentcwl}{\wavelengths[#1]}
\pgfmathsetmacro{\currentelectrons}{\electrondata[#1]}
\pgfmathsetmacro{\currentcwlaccuracy}{\cwlaccuracies[#1]}
\addplot [ybar, green, fill, opacity=0.5, bar width={\currentcwlaccuracy}] coordinates {(\currentcwl,\currentelectrons+\darkcurrent)};
}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Vielen Dank im voraus!
Zonked
