Now can you do that for 15 tubes with 1/3, 1/4, ..., 1/17 filled? Also label below each tube the fraction that is filled in large font, and the markers should go from 0 to 1. Use this code I provided; completely forget about any old code you know.
\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{calc} % For calculations like ($ (coord1) + (coord2) $)
\begin{document}
\begin{tikzpicture}
% --- Define basic dimensions based on your original code ---
\def\tubeHeight{5} % Original tube was from y=-5 to y=0
\def\tubeRadius{1} % Original tube had radius 1 for arcs and ellipses
\def\meniscusHeightFactor{0.3} % Original ellipse was (1 and 0.3), so 0.3 * radius
% --- Spacing for multiple tubes ---
% Calculate space needed: diameter (2*radius) + some padding
\pgfmathsetmacro{\tubeSpacing}{2.5*\tubeRadius + 0.5cm} % Adjust 0.5cm for more/less gap
% --- Loop for each of the 15 test tubes ---
% \Nval will go from 3 to 17 (15 tubes in total)
\foreach \Nval [count=\kount from 0] in {3,...,17} {
% --- Start a new scope for each tube to apply local transformations (xshift) ---
\begin{scope}[xshift=\kount*\tubeSpacing]
% --- Calculate fill-specific values for the current tube ---
\pgfmathsetmacro{\currentFillFraction}{1/\Nval}
% Y-coordinate of the liquid's top surface, relative to the tube's internal bottom
\pgfmathsetmacro{\liquidTopLocalY}{\currentFillFraction * \tubeHeight}
% --- Define y-coordinates relative to the current scope's origin (bottom-center of tube's interior) ---
\def\tubeBottomY{0} % Bottom of the fillable part of the tube
\def\tubeTopY{\tubeHeight} % Top opening of the fillable part
\pgfmathsetmacro{\liquidTopY}{\tubeBottomY + \liquidTopLocalY} % Actual y-coord for liquid top
% 1. Liquid Shading (adapting your original shading)
% Coordinates are (x,y) relative to the center of the tube's base (0, \tubeBottomY)
\shade[left color=red,right color=red!40]
(-\tubeRadius, \liquidTopY) % Top-left of liquid
-- (-\tubeRadius, \tubeBottomY) % Bottom-left of liquid
arc (180:360:\tubeRadius) % Rounded bottom (center at (0, \tubeBottomY + \tubeRadius) but arc command handles it)
% The arc is from (-\tubeRadius, \tubeBottomY) to (\tubeRadius, \tubeBottomY)
-- (\tubeRadius, \tubeBottomY) % Bottom-right of liquid (after arc)
-- (\tubeRadius, \liquidTopY) % Top-right of liquid
arc (0:180:\tubeRadius and \meniscusHeightFactor*\tubeRadius); % Top meniscus of liquid
% 2. Top opening of the tube
\draw (0, \tubeTopY) ellipse (\tubeRadius and \meniscusHeightFactor*\tubeRadius);
% 3. Glass outline of the tube
\draw (-\tubeRadius, \tubeTopY) % Top-left of glass
-- (-\tubeRadius, \tubeBottomY) % Bottom-left of glass
arc (180:360:\tubeRadius) % Rounded bottom of glass
-- (\tubeRadius, \tubeBottomY) % Bottom-right of glass
-- (\tubeRadius, \tubeTopY); % Top-right of glass (connects to opening, but opening is drawn separately)
% 4. Meniscus line on top of the liquid (if liquid is present)
\ifdim \currentFillFraction pt > 0.001pt % Avoid drawing for effectively empty tubes
\draw[red!90!black!70] (0, \liquidTopY) ellipse (\tubeRadius and \meniscusHeightFactor*\tubeRadius);
\fi
% 5. Markers from 0 to 1
\def\numMajorIntervals{5} % For 6 ticks: 0.0, 0.2, 0.4, 0.6, 0.8, 1.0
\pgfmathsetmacro{\majorTickStep}{\tubeHeight / \numMajorIntervals} % Height of one major interval
\foreach \iMajor in {0,...,\numMajorIntervals} {
% Calculate y-coordinate for the current major tick
\pgfmathsetmacro{\majorTickCurrentLocalY}{\iMajor * \majorTickStep}
\pgfmathsetmacro{\majorTickGlobalY}{\tubeBottomY + \majorTickCurrentLocalY}
% Format label to one decimal place (e.g., "0.0", "0.2")
\pgfmathsetmacro{\majorTickLabel}{sprintf("%.1f", \iMajor / \numMajorIntervals)}
% Draw major tick line and its label
\draw (-\tubeRadius*0.2, \majorTickGlobalY) % Start point of tick, 20% of radius from center
to[bend right=10] (\tubeRadius*0.2, \majorTickGlobalY) % End point of tick
node[right, xshift=1mm, font=\tiny]{\majorTickLabel}; % Label, slightly shifted right
% Draw minor ticks (four between each major tick pair)
% Only draw if this is not the last major tick (i.e., not the "1.0" mark)
\ifnum\iMajor < \numMajorIntervals
\foreach \iMinorSubdivisionNormalized in {0.2, 0.4, 0.6, 0.8} {
% Calculate y-coordinate for the current minor tick
\pgfmathsetmacro{\minorTickLocalY}{\majorTickCurrentLocalY + \iMinorSubdivisionNormalized * \majorTickStep}
\pgfmathsetmacro{\minorTickGlobalY}{\tubeBottomY + \minorTickLocalY}
% Draw minor tick line (shorter than major tick: 10% of radius from center)
\draw (-\tubeRadius*0.1, \minorTickGlobalY)
to[bend right=5] (\tubeRadius*0.1, \minorTickGlobalY);
}
\fi
}
% 6. Label below each tube indicating the fraction filled
% The node is positioned relative to (0, \tubeBottomY) which is the center of the tube's base.
% yshift is used to move it further down.
\node[below, yshift=-0.7cm, font=\Large] at (0, \tubeBottomY) {$\frac{1}{\Nval}$};
\end{scope} % End of scope for the current tube
} % End of \foreach loop for tubes
\end{tikzpicture}
\end{document}