pgfplots
- How to get figure to take full column widthby crayman9 on July 9, 2025 at 6:45 pm
I would like the figure here to take the full column width. I'm giving the argument "width=\columnwidth." Why does it end up less than the column width? I can instead use "width=1.17*\columnwidth" which gives the correct width approximately, but then puts the figure at the end of the document, which seems weird when there is plenty of vertical space for it at the point of insertion. \documentclass[twocolumn]{article} \usepackage[margin=0.5in]{geometry} \usepackage{tikz} \usepackage{pgf} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{lipsum} \begin{document} \lipsum[1-11] \textbf{Important:} \pgfmathsetmacro{\latmin}{28.6615} \pgfmathsetmacro{\latmax}{33.9651} \pgfmathsetmacro{\latwidth}{\latmax - \latmin} \pgfmathsetmacro{\longmin}{-96.6307} \pgfmathsetmacro{\longmax}{-93.5031} \pgfmathsetmacro{\longwidth}{\longmax - \longmin} \begin{figure}[t] \centering \begin{tikzpicture} \begin{axis}[ xmin=\longmin, xmax=\longmax, ymin=\latmin, ymax=\latmax, axis equal image=false, unit vector ratio=1 1.16, axis lines=none, grid=none, clip=true, width=\columnwidth, height=50cm, clip mode=individual, ] \draw (\longmin,\latmin) rectangle (\longmax,\latmax); \end{axis} \end{tikzpicture} \end{figure} \lipsum[12-28] \end{document}
- Why \clip does not affect \addplotby crayman9 on July 9, 2025 at 5:09 am
In the attached example, I have a \clip defined, attempting to remove drawing from the upper right quadrant. It works for the circle, but not for the \addplot. How can I get it to work for the latter? \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ axis equal, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5, grid=both, minor tick num=2, ] \begin{scope}[even odd rule] \clip (rel axis cs: 0,0) rectangle (rel axis cs: 1,1) (axis cs:0,0) rectangle (axis cs:1.5,1.5); \fill [red] (0,0) circle (1); \addplot[ only marks, mark=*, mark size=3.0pt, color=black ] table[ x=Longitude, y=Latitude, col sep=comma ] {test_points.csv}; \end{scope} \end{axis} \end{tikzpicture} \end{document} test_points.csv contains the following: Latitude,Longitude -0.5,-0.5 0.5,-0.5 -0.5,0.5 0.5,0.5
- How to invert a mask in a drawingby crayman9 on July 9, 2025 at 3:44 am
Here is an example latex tikzpicture axis plot where I've clipped the upper right quadrant of a circle. How can I invert this? That is, rather than display only the upper right quadrant, display everything but the upper right quadrant. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ axis equal, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5, grid=both, minor tick num=2, ] \pgfplotsextra{% \clip (axis cs:0,0) rectangle (axis cs:1.5,1.5); } \fill [red] (0,0) circle (1); \end{axis} \end{tikzpicture} \end{document}
- pgfplotstable interprets datum as numberby Sören on July 8, 2025 at 2:01 pm
I'm trying to display a table from a .csv in LaTeX with the pgfplotstable package. For some reason it tries to interpret a datum as number. In my code I have: \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage{pgfplotstable} \usepackage{geometry} \geometry{margin=2cm} \pgfplotsset{compat=1.18} \begin{document} \pgfplotstableread[col sep=comma]{Stunden_Juni.csv}\stunden \pgfplotstabletypeset[ columns/Datum/.style={string type}, columns/Kunde/.style={string type}, columns/Projekt/.style={string type}, columns/Startzeit/.style={string type}, columns/Endzeit/.style={string type}, columns/Stunden/.style={column type=r, fixed, precision=2}, every head row/.style={before row=\hline, after row=\hline}, every last row/.style={after row=\hline} ]{\stunden} \end{document} my .csv looks like this: Datum,Kunde,Projekt,Startzeit,Endzeit,Stunden 2025-06-16,Benecke,SAP Umstellung,8:00,12:00,4 2025-06-16,Benecke,SAP Umstellung,12:30,16:00,3.5 I tried to format the Datum with "dd.mm.yyyy" and "mm/dd/yyyy" as well and it didn't work. Error Message: Package PGF Math Error: Could not parse input '2025-06-16' as a floating point number, sorry. The unreadable part was near '-06-16'.. See the PGF Math package documentation for explanation. Type H <return> for immediate help. ... l.27 ]{\stunden} This error message was generated by an \errmessage command, so I can't give any explicit help. Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.
- Set colour via every axis plot/.styleby Atcold on July 7, 2025 at 9:57 pm
I'm trying to set the plot options from the axis style usig every axis plot/.append style, but it's not working. What am I doing wrong? \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \matrix{ \begin{axis}[ every axis plot/.append style={ycomb, red}, ] \addplot+ {max(1 - x^2/10, 0)}; \end{axis}& \begin{axis} \addplot+ [ycomb, red] {max(1 - x^2/10, 0)}; \end{axis}\\ }; \end{tikzpicture} \end{document} Getting there… applying Jasper's suggestion. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \matrix{ \begin{axis}[ every axis plot post/.append style={ycomb, red, mark=*}, ] \addplot {max(1 - x^2/10, 0)}; \end{axis}& \begin{axis} \addplot [ycomb, red, mark=*] {max(1 - x^2/10, 0)}; \end{axis}\\ }; \end{tikzpicture} \end{document} Done, thanks to StefanH's comment. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \matrix{ \begin{axis}[ every axis plot post/.append style={ycomb, red, mark=*, mark options={fill=red}}, ] \addplot {max(1 - x^2/10, 0)}; \end{axis}& \begin{axis} \addplot [ycomb, red, mark=*] {max(1 - x^2/10, 0)}; \end{axis}\\ }; \end{tikzpicture} \end{document}
- pgfplots: Restoring x-axis label positions when using yscale=-1 for the axis environmentby schtandard on July 7, 2025 at 4:24 pm
I recently found a way to use a "Logarithmic scale" for negative values with pgfplots by inverting the whole plot and then inverting the labels back. Of course, this has lots of side effects like transforming the anchors of the plot, so care needs to be taken when building larger drawings including such a plot. Now, one way to contain the side effects a bit better is to only transform the axis environment, not the entire tikzpicture. Indeed, this has the pleasant effect of restoring the plot anchors to the natural positions. However, I can't figure out how to fix the placement of the x-tick labels and the x-label (where the latter follows the former). Due to the inversion, the tick labels appear above the x-axis, not below it. I have tried a bunch of placement options, but each time something ends up in the wrong place; either the tick labels or the axis label. I'm sure there is a way, but I am unable to see it in the forest of pgfplots options. I'm sure I could do it by manually placing the labels in absolute terms, but I want to preserve the pre-existing placement features, that is: The x-tick labels should be aligned below the x-axis. The x-label should be aligned below the x-tick labels (depending on their heights). How can this be achieved? Here is an MWE. The first plot is the desired result (except for the anchor positions), the second plot is the second approach with the not quite right x-axis labels. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} [yscale=-1] \begin{semilogyaxis}[ name=test, y filter/.expression={ln(-y)}, log number format basis/.code 2 args={$-#1^{\pgfmathprintnumber{#2}}$}, every axis label/.append style={yscale=-1}, every tick label/.append style={yscale=-1}, xticklabel pos=top, xlabel=$x$ axis, ylabel=$y$ axis, ] \addplot {-.1 - x^2}; \end{semilogyaxis} \draw [red] (test.north west) circle [radius=.2cm]; \draw [green] (test.below south west) circle [radius=.2cm]; \end{tikzpicture} \begin{tikzpicture} \begin{semilogyaxis}[ name=test, yscale=-1, y filter/.expression={ln(-y)}, log number format basis/.code 2 args={$-#1^{\pgfmathprintnumber{#2}}$}, xticklabel pos=top, xlabel=$x$ axis, ylabel=$y$ axis, ] \addplot {-.1 - x^2}; \end{semilogyaxis} \draw [red] (test.north west) circle [radius=.2cm]; \draw [green] (test.below south west) circle [radius=.2cm]; \end{tikzpicture} \end{document}
- pgfplots: Using color of colormap after another color is already selectedby schtandard on July 5, 2025 at 2:20 pm
Using the key color of colormap I can pick a plotting color from any existing colormap. However, this does not seem to work when a color has already been explicitly set. In the following example I try to set the color using the key three times, this should result in green plots. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis} \addplot+ [color of colormap=800 of viridis] {0}; \addplot [color of colormap=800 of viridis] {x}; \addplot [color=red, color of colormap=800 of viridis] {2 * x}; \end{axis} \end{tikzpicture} \end{document} In the first plot, the key has no effect at all. In the second plot it works, but I have to sacrifice all presets (like the markers in this example). In the third plot, it again does not have an effect. Why is this happening? How can I pick a color using color of colormap after another color has already been set?
- pgfplots: Using set layers in an overlay pictureby schtandard on July 5, 2025 at 1:58 pm
Using pgfplots, I want to draw a plot as an overlay picture, making use of layers inside that plot. However, when I say \begin{tikzpicture} [overlay] \pgfplotsset{set layers} \begin{axis} \end{axis} \end{tikzpicture} I get two ! Dimension too large. errors. pgfplots seems to attempt to set both unit lengths (\pgf@x and \pgf@y) to -32000.0pt. Why is that and how can I avoid it? For tinkering, here is a slightly more useful MWE. Interestingly, the result looks fine in this example. (In larger pictures, the errors do cause havoc, though.) \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} [remember picture] \draw [green] coordinate (test) circle [radius=5cm]; \end{tikzpicture} \begin{tikzpicture} [remember picture, overlay] \pgfplotsset{set layers} \begin{axis} [at=(test), anchor=center, ymajorgrids] \addplot+ {x^2}; \begin{pgfonlayer}{axis grid} \fill [red] (axis cs:3,20) circle [radius=2cm]; \end{pgfonlayer} \end{axis} \end{tikzpicture} \end{document}
- pgfplots: Math font for 'extra y tick labels'by cis on July 5, 2025 at 4:11 am
What do I have to set so that the extra y tick labels are also set in math mode? Note: I left all other settings as they were. \documentclass[margin=5pt, tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \def\Ymin{-20} \def\Ymax{21} \pgfmathtruncatemacro\YminPre{\Ymin+5} \pgfmathsetlengthmacro\Yenlarge{3.25mm} \begin{tikzpicture}[] \begin{axis}[ xmin = -5, xmax=5, ymin =\Ymin, ymax = \Ymax, axis lines = middle, axis line style={->, >=latex}, xlabel={$x$}, ylabel={$y$}, x label style={at={(ticklabel* cs:1.00)}, inner sep=5pt, anchor=north}, y axis line style={shorten >=-\Yenlarge, shorten <=-\Yenlarge+1.5mm}, y label style={at={(ticklabel* cs:1.00)}, inner sep=2pt, anchor=east, yshift=\Yenlarge}, xtick={-5,-4,...,5}, enlarge x limits={0.075}, % y>0 ticks left ====================== ytick={20,15,...,-20}, yticklabel={\pgfmathprint{\tick>0 ? int(\tick) : {}} }, % y<0 ticks right =================== extra y ticks={\Ymin,\YminPre,...,-5}, extra y tick labels={\Ymin,\YminPre,...,-5}, extra y tick style = {tick label style={anchor=west, inner xsep=.5em}, /pgf/number format/assume math mode=true% no effect }, minor y tick num={4},% for complete y-axis! ] \addplot[red] {x}; \end{axis} \end{tikzpicture} \end{document}
- pgfplot: Gamma function for x<0 without y-gapsby cis on July 4, 2025 at 10:00 am
I would like to pgfplot the Gamma function for x>0 and x<0 (in the x-interval as shown); but without these "y-gaps": In the following code I use the Stirling-approximation G(\x)=sqrt(2*pi)*\x^(\x-0.5)*exp(-\x)*exp(1/(12*\x)) for x>0; and Euler's reflection formula for x<0. But to avoid these y-gaps I need to set a very huge sample number. This needs long calculation durances. What could I do better. Is there maybe a trick? \documentclass[margin=5mm, tikz]{standalone} %\usepackage{pgfplotstable} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture}[ trig format=rad, declare function={ G(\x)=sqrt(2*pi)*\x^(\x-0.5)*exp(-\x)*exp(1/(12*\x));% x>0 gamma(\x)=(\x>=0 ? G(\x) : pi/(G(1 - \x)*sin(pi*\x));% x<0 - 2/2 } ] \begin{axis}[ %xmin = -4.9, xmax = 5.1, %ymin = -3.5, ymax = 3.5, restrict y to domain=-5.05:8.05, axis lines = middle, xlabel={$x$}, ylabel={$y$}, x label style={at={(ticklabel* cs:1.00)}, inner sep=5pt, anchor=north}, y label style={at={(ticklabel* cs:1.00)}, inner sep=2pt, anchor=south east}, ytick={-4,-2,...,4}, minor y tick num={1}, xtick={-5,...,5}, enlarge x limits={0.075}, %enlarge x limits={0.05, lower}, %enlarge y limits=0.125, ] % x>0: \addplot[blue, samples=222, smooth, domain =0:5] {gamma(x)}; % x<0: \addplot[color=red, samples=222, smooth, domain=-1:0] {gamma(x)}; \addplot[color=red, samples=444, smooth, domain=-2:-1] {gamma(x)}; \addplot[color=red, samples=777, smooth, domain=-3:-2] {gamma(x)}; \addplot[color=red, samples=888, smooth, domain=-4:-3] {gamma(x)}; %\addplot[color=red, samples=3333, smooth, domain=-5:-4] {gamma(x)}; \foreach \n in {0,...,-5}{% \addplot [densely dashed, thin] (\n, x); }% \end{axis} \end{tikzpicture} \end{document}
- Enable minor ticks without changing major grid in logarithmic axisby jeirual on July 4, 2025 at 7:14 am
I have a semi-logarithmic plot, and I noticed that when the range is to large, minor ticks for the logarithmic axis disappear. I tried using max space between ticks=20, but it actually changes also the major grid in both axis. Is it possible to keep the minor ticks of the logarithmic axis without changing the major grid ? Here is my MWE: \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{semilogyaxis}[grid=major, domain=0:5, ymin=1e0, ymax=1e8, % max space between ticks=20 %% <-- allowing minor ticks ] \addplot {10^x)}; \end{semilogyaxis} \end{tikzpicture} \end{document}
- What is the most elegant way to shift the xy-plane to 𝑧=0 in a 3D TikZ diagram?by Marco Moldenhauer on June 28, 2025 at 3:42 am
I'm trying to draw a 3D diagram, and I want the xy-plane of the coordinate system to appear at z=0 — in effect, "lifting" the standard xy-plane to a higher position in the 3D coordinate space, as shown in the image below. What would be the most elegant and idiomatic way to achieve this? my code \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} [ % Define a paremtric curve declare function = { fx(\t) = 0.25+\t^3; fy(\t) = 0.5+1.6*\t; fz(\t) = 1-\t^2; Samples = 8; DomLowerBound = 0; DomUpperBound = 1.2; }, ] \begin{axis} [%% view={120}{45}, plot box ratio=1 1 1, width=22cm, height=12cm, xmin=-0.5, xmax=2.5, ymin=-0.5, ymax=2.5, zmin=-1, zmax=1.5, grid, grid style={very thin, gray}, trig format plots=rad, enlargelimits=false, xlabel=$x$, ylabel=$y$, zlabel=$z$, xtick={0.0,0.5,...,2}, ytick={0.0,0.5,...,2} ]%% % Plot the parametric surface using the defined functions \addplot3 [ variable=t, mesh, domain=DomLowerBound:DomUpperBound, samples=Samples ] ( { fx(t) }, { fy(t) }, { fz(t) } ); \addplot3 [ variable=t, mesh, domain=DomLowerBound:DomUpperBound, samples=Samples, gray ] ( { fx(t) }, { fy(t) }, { -1 } ); \pgfplotsinvokeforeach {0,DomUpperBound/(Samples-1),...,DomUpperBound} { \draw[gray, dotted] ({fx(#1)},{fy(#1)},-1) -- ({fx(#1)},{fy(#1)},{fz(#1)}); } \end{axis} \end{tikzpicture} \end{document} my output
- Use foreach loop variable in path coordinatesby Franz on June 27, 2025 at 12:36 pm
I have the following code: \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{fillbetween} \begin{document} \begin{tikzpicture} \begin{axis}[% axis x line=center, axis y line=center, xmax=2., xmin=-1., ymax=2., ymin=-1., ] \foreach \eps in { 1.0, 0.39810717, 0.15848932, 0.06309573, 0.01 }{ \addplot[ domain=\eps/\pgfkeysvalueof{/pgfplots/xmax}:\pgfkeysvalueof{/pgfplots/xmax}, samples=100, mark=none, name path=reg, ] {\eps/x}; % \path [name path=xaxis] % (\eps/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- % (\pgfkeysvalueof{/pgfplots/xmax}, 0.0); % \addplot[ % gray, % opacity=0.5 % ] fill between [of=reg and xaxis]; } \end{axis} \end{tikzpicture} \end{document} Adding the commented lines I get an Undefined control sequence \eps error. Using \eps in the definition of the function and domain works. But apparently I cannot use it in the coordinates of a node. Could someone give me a brief explanation why this is the case? How can I make use of the value of \eps? EDIT: Using \closedcycle as suggested by samcarter_is_at_topanswers.xyz does not work for me as I need to use \eps also in other places. This is what I want the plot to look like (loop unrolled for two cases): \path [name path=yaxis] (0.0, 0.0) -- (0.0, \pgfkeysvalueof{/pgfplots/ymax}); \addplot[ domain=1/\pgfkeysvalueof{/pgfplots/xmax}:\pgfkeysvalueof{/pgfplots/xmax}, samples=100, mark=none, name path=reg, ] {1/x}; \path [name path=xaxis] (1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (\pgfkeysvalueof{/pgfplots/xmax}, 0.0); \addplot[ gray, opacity=0.5 ] fill between [of=reg and xaxis]; \path [name path=toinf] (1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (1/\pgfkeysvalueof{/pgfplots/xmax}, \pgfkeysvalueof{/pgfplots/ymax}); \addplot[ gray, opacity=0.5 ] fill between [of=yaxis and toinf]; \addplot[ domain=0.1/\pgfkeysvalueof{/pgfplots/xmax}:\pgfkeysvalueof{/pgfplots/xmax}, samples=100, mark=none, name path=reg, ] {0.1/x}; \path [name path=xaxis] (0.1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (\pgfkeysvalueof{/pgfplots/xmax}, 0.0); \addplot[ gray, opacity=0.5 ] fill between [of=reg and xaxis]; \path [name path=toinf] (0.1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (0.1/\pgfkeysvalueof{/pgfplots/xmax}, \pgfkeysvalueof{/pgfplots/ymax}); \addplot[ gray, opacity=0.5 ] fill between [of=yaxis and toinf]; Also using \closedcycle results in the axis lines been drawn multiple times as seen here:
- Using \foreach with declared functions inside axis environment (TikZ/pgfplots)by Marco Moldenhauer on June 27, 2025 at 9:01 am
I'm trying to use a \foreach loop within a pgfplots \begin{axis}...\end{axis} environment to draw vertical lines from the XY-plane up to a parametric 3D curve defined by custom functions. I've defined functions using declare function for fx(t), fy(t), and fz(t), and I can successfully use them in an \addplot3 command. However, when I try to use them within a \foreach loop to draw lines using \draw, I get an error. The problematic line is: \draw[red] (axis cs:{fx(\t)},{fy(\t)},-1) -- (axis cs:{fx(\t)},{fy(\t)},{fz(\t)}); my Code \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} [ % Define a paremtric curve declare function = { fx(\t) =(\t)^2; fy(\t) =\t*(1-\t); fz(\t) =1-\t; }, ] \begin{axis} [%% view={45}{26}, plot box ratio=1 1 1, width=22cm, height=12cm, xmin=-2.5, xmax=2.5, ymin=-2.5, ymax=2.5, zmin=-1, zmax=1.5, grid, grid style={very thin, gray}, trig format plots=rad, enlargelimits=false, ]%% % Plot the parametric surface using the defined functions \addplot3 [ variable=t, mesh, domain=0:1.2, samples=20 ] ( { fx(t) }, { fy(t) }, { fz(t) } ); \foreach \t in {0,0.2,...,1} { %% Returns an error %\draw[red] (axis cs:{fx(\t)},{fy(\t)},-1) -- (axis cs:{fx(\t)},{fy(\t)},{fz(\t)}); } \end{axis} \end{tikzpicture} \end{document} My Output
- How can I define and use parametric functions in TikZ/pgfplots for 3D plotting and later reference them for drawing other lines?by Marco Moldenhauer on June 27, 2025 at 8:12 am
I'm trying to draw a 3D parametric curve ⟨x(t),y(t),z(t)⟩ using \addplot3 in TikZ/pgfplots, but I want to predefine the functions for x(t), y(t), and z(t) so that I can reuse them later in my drawing, for instance, to draw lines between specific coordinate points. My Code \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} [%% view={45}{26}, width=22cm, height=12cm, xmin=-2.5, xmax=2.5, ymin=-2.5, ymax=2.5, zmin=-1, zmax=1.5, grid, grid style={very thin, gray}, trig format plots=rad, enlargelimits=false, ]%% % Define the parametric functions for t->x, t->y, t->z \def\x(t){t^2} \def\y(t){t*(1-t)} \def\z(t){1-t} % Plot the parametric surface using the defined functions \addplot3 [ variable=t, mesh, domain=0:1.2, samples=20 ] ( { \x(t) }, { \y(t) }, { \z(t) } ); % Draw vertical line from <x(0),y(0),-1> to <x(0),y(0),z(0)> \draw[red] (axis cs:{\x(0)},{\y(0)},-1) -- (axis cs:{\x(0)},{\y(0)},{\z(0)}); \end{axis} \end{tikzpicture} \end{document} log: 46: Use of \x doesn't match its definition. \end{axis} 46: Use of \y doesn't match its definition. \end{axis} 46: Use of \z doesn't match its definition. \end{axis} 46: Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ')'). \end{axis} 46: Missing number, treated as zero. \end{axis} 46: Illegal unit of measure (pt inserted). \end{axis} 46: Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ')'). \end{axis} 46: Missing number, treated as zero. \end{axis} 46: Illegal unit of measure (pt inserted). \end{axis} 46: Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ')'). \end{axis} 46: Missing number, treated as zero. \end{axis} 46: Illegal unit of measure (pt inserted). \end{axis} 46: Use of \x doesn't match its definition. \end{axis} 46: Use of \y doesn't match its definition. \end{axis} 46: Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ')'). \end{axis} 46: Missing number, treated as zero. \end{axis} 46: Illegal unit of measure (pt inserted). \end{axis} 46: Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in ')'). \end{axis} 46: Missing number, treated as zero. \end{axis} 46: Illegal unit of measure (pt inserted). \end{axis} : running in backwards compatibility mode (unsuitable tick labels; missing features). Consider writing \pgfplotsset{compat=1.18} into your preamble.
- \pgfplotsinvokeforeach with \pgfmathsetmacro doesn't workby Stanislas Remy on June 24, 2025 at 4:20 pm
I would like to draw straight line segments in order to highlight the abscissa and ordinate for some points on the curve of 2^x, and for that I would like to make a loop with \pgfplotsinvokeforeach and \pgfmathsetmacro but it does not work. I have those segments only for the first loop, and I do not understand why. Thanks in advance. % !TeX program = lualatex \documentclass[a4paper,10pt,twoside]{scrbook} \usepackage{tikz} \usetikzlibrary{arrows.meta} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \def\xm{0} \def\XM{3} \def\ym{0} \def\YM{8} \begin{tikzpicture}[x=1.0cm, y=1.0cm, scale=1, every node/.style={scale=1}] \begin{axis} %~~~~~~~~~~~ [ /pgf/number format/.cd , use comma,1000 sep={~} , anchor = origin, %,at={(0pt,0pt)}%, disabledatascaling, clip = false, scale only axis = true, x = 4cm, y = 1cm, %width = longueurcm, %height = hauteurcm, xmin = \xm, xmax = \XM, ymin = \ym, ymax = \YM, xlabel = $x$, ylabel = $y$, axis x line = middle, % left,% right,% none,% axis y line = middle, %left,% right,% none,% x axis line style = {arrows={-Stealth[inset=2pt, angle=30:7pt]},shorten >=-10pt, shorten <=-10pt}, y axis line style = {arrows={-Stealth[inset=2pt, angle=30:7pt]},shorten >=-10pt, shorten <=-10pt}, xtick = {\xm,...,\XM}, % \empty, % minor x tick num = 5, %xticklabels = {label pos 1,label pos 2,...,label pos n}, ytick = {\ym,...,\YM}, % \empty, % minor y tick num = 1, %yticklabels = {label pos 1,label pos 2,...,label pos n}, x tick label style = {anchor=north,yshift=-1ex,font=\normalsize,fill=white,inner sep=1pt}, y tick label style = {anchor=east,xshift=-1ex,font=\normalsize,fill=white,inner sep=1pt}, xlabel style = {anchor=west,at={(ticklabel* cs:1.0)},xshift=2ex}, ylabel style = {anchor=south,at={(ticklabel* cs:1.0)},yshift=2ex}, grid = major,% both, % minor, % %grid style = {line width=.1pt,couleur}, %major grid style = {line width=.2pt,couleur}, %minor grid style = {line width=.2pt,couleur}, ] %~~~~~~~ \addplot [id={id}, domain=\xm:\XM, samples=19, smooth, mark=*, ultra thick, color=red] gnuplot {2**x} node [right=10pt, pos=0.1, color=red, fill=white, inner sep=1pt] {}; \pgfplotsinvokeforeach{1,2,3}{ \pgfmathsetmacro{\abscisse}{1/#1}; \pgfmathsetmacro{\ordonnee}{pow(2,1/#1)}; \draw [densely dashed,color = red,thick] (\abscisse,0) -- (\abscisse,\ordonnee)-- (0,\ordonnee) ; } %~~~~~~~~~ \end{axis} \end{tikzpicture} \end{document}
- Pgfplots on Fourier Transform Infrared Spectroscopy Graphby kalakay on June 23, 2025 at 8:07 am
How to show the coordinates of peak points and their labels on the Fourier Transform Infrared Spectroscopy test result graph automatically? \documentclass[border=5pt]{standalone} \usepackage{fouriernc,erewhon} \usepackage{pgfplots} \pgfplotsset{width=12cm, compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel={Wavenumber (cm\textsuperscript{-1})}, ylabel={Transmittance (\%)}, xmin=400, xmax=4000, ymin=0, ymax=100, grid=both, x dir=reverse, % <-- Ini opsi untuk membalik sumbu-x legend style={at={(0.98,0.15)}, anchor=north east} ] \addplot [blue, thick] table [x index=0, y index=1, col sep=comma] {alkalisasi.csv}; \legend{FTIR Spectrum} \end{axis} \end{tikzpicture} \end{document} Here is "alkali.csv" file.
- different formatting of numbers on axesby Nicolas on June 22, 2025 at 6:34 am
For my graph, the number settings between the abscissa and ordinate axes are not the same. For the ordinates, no problem: I manage to format them correctly with \pgfplotsset{/pgf/number format/.cd,fixed,precision=2,use comma} However, how can I configure the abscissa axis differently (in thousands: 1,000, 1,500, 2,000, etc.)? %%COMPILé AVEC XeLaTeX % \documentclass[10pt,border=1mm,tikz]{standalone} \usepackage[dvipsnames,svgnames]{xcolor} \usepackage{lmodern} \usepackage{pgfplots}\pgfplotsset{compat=newest} \pgfplotsset{/pgf/number format/.cd,fixed,precision=2,use comma} \pgfplotsset{compat=newest} % Permet l'affichage de deux axes y \usepackage[french]{babel} \usepackage{siunitx}% unités et écriture de valeurs \begin{document} \footnotesize \begin{tikzpicture} \begin{axis}[% mise en forme du graphique : xmin=0,xmax=3000, ymin=0,ymax=0.16, xlabel=durée ($\unit{\s}$), ylabel=Absorbance, ytick distance=0.02, minor x tick num=1, axis x line=bottom,axis y line = left, legend pos=south east, ] \addplot[blue, smooth, domain=0:2900] {0.154*(1-exp(-\x/500))}; \addlegendentry{modélisation} \end{axis} \end{tikzpicture} \end{document}
- Disappearing arrows in PGF plot of linear inequalitiesby Mohan Fitzgerald on June 18, 2025 at 7:43 pm
I'm trying to make materials for a high school math class. I've finally got a decent-looking plot of a system of linear equalities but am struggling with making sure the arrows at the end of each line don't disappear. I know that I can get the arrows to show up if I restrict the domain to a smaller interval, but then the shading is kind of wacky. I'd love to tell LaTex to put the arrow where the line and the edge of the graph intersect or something? I want the arrows to be on either end of the line right where the line intersects the end of the graph. And while we're at it--how do I get the axis to show arrows going in both directions, and not just in the positive direction as it is doing now. enter code here \documentclass{article} \usepackage{pgfplots} \usepgfplotslibrary{fillbetween} \usetikzlibrary{patterns} \pgfplotsset{compat=1.17} \begin{document} \begin{center} \begin{tikzpicture} \begin{axis}[ axis lines=middle, axis line style={-stealth,shorten >=-3mm}, xmin=-5,xmax=5, ymin=-5,ymax=5, xlabel=$x$, every axis x label/.style={at={(xticklabel cs:1,0)}, yshift=1.8em, anchor=south west}, ylabel=$y$, every axis y label/.style={at={(yticklabel cs:1,0)}, xshift=2.3em,yshift=0.2em, anchor=south east}, grid=both, grid style={draw=gray!25}, tick label style={font=\tiny}, xtick={-5, -4, ..., 5}, ytick={-5, -4, ..., 5}, yticklabel style={xshift=-0.5ex}, minor tick num=1, minor tick length=0.5ex, minor x tick style={yshift=0.25ex}, minor y tick style={xshift=0.25ex}, ] \addplot[name path=F, domain={-4:5},<->,dotted,thick]{x*2+3}; \node at (-4.25,-1) [below, font=\small] {$G(x)$}; \path[name path=neginf] (-5,-5) -- (5,-5); \addplot[name path=G, domain={-5:5},<->,thick]{x+2}; \node at (-2.5,-4) [font=\small] {$F(x)$}; \path[name path=posinf] (-5,5) -- (5,5); \addplot[fill=black, fill opacity=0.6,pattern=north east lines] fill between [of=F and neginf, soft clip={domain=-5:5}]; \addplot[fill=black, fill opacity=0.1]fill between [of=G and posinf, soft clip={domain=-5:5}]; \fill [name intersections={of=F and G, by={a}}] (a) circle (1.5pt); \end{axis} \end{tikzpicture} \end{center} \end{document}
- Misplaced alignment tab character & with pgfplots and `input` [closed]by Nukesub on June 18, 2025 at 3:51 pm
I am encountering the following issue and would appreciate suggestions on how to resolve it. I have a thesis that will contain many plots. I have it modularized so that within the thesis text I call a figure by doing \begin{figure} \centering \inputTikz{my_figure} \caption{A nice caption} \end{figure} And the macro \inputTikz is \newcommand{\inputTikz}[1]{% \tikzexternalenable \tikzsetnextfilename{#1} \pgfplotsset{ table/search path={tikz/#1}, } \input{tikz/#1/#1.tikz} \tikzexternaldisable } And separately I have a .tikz source file that contains the code to create the figure such as this. % my_figure.tikz \begin{tikzpicture} \begin{axis} \addplot+ [ sharp plot, ] coordinates {% (0,0) (1,2) (2,3) }; \end{axis} \end{tikzpicture} It is difficult to include any more than this as the thesis document is quite large and the figures rely on external data plotted using table. The document compiles fine as it. But if I include a legend in the plot like so \begin{tikzpicture} \begin{axis}[ legend entries = {my plot} % added this line ] \addplot+ [ sharp plot, ] coordinates {% (0,0) (1,2) (2,3) }; \end{axis} \end{tikzpicture} then I get the following error. Misplaced alignment tab character &. \pgf@matrix@cell@cont ...st@nextcell@options {#1}&LaTeX I assume this means the code pgfplots uses to create the legend contains some & which are not being protected. For context, I am using the following: lualatex 1.17.0 TeX Live 2023 memoir 3.7.19 pgfplots 1.18.1 tikz 3.1.10
- dimension too large when graphicby joseline on June 18, 2025 at 2:38 am
when try plot this function i get error "dimension too large" this is the code and graphic I am interested in the region of positive x \begin{tikzpicture}[>=stealth] \begin{axis}[ xmin=-6,xmax=8, ymin=-5.5,ymax=7, axis x line=middle, axis y line=middle, axis line style=->, height=13.0cm, width=13.0cm, extra x ticks = {0}, xlabel={$x$}, ylabel={$C(x)$}, xtick={-2,4,-4,-3}, ytick={1,3}, ] node[pos=0.65,anchor=south west]{}; \addplot[no marks,ultra thick,red,-] expression[domain=0.05:18,samples=100]{ (256)*(e^(x - 4))*(1/x^4)}; \addplot [dashed,thick,black] coordinates {(0 ,1) (4 ,1)}; \addplot [dashed,thick,black] coordinates {(4 ,0) (4 ,1)}; \addplot [dashed,thick,black] coordinates {(-3 ,3) (-3 ,0)}; \addplot [dashed,thick,black] coordinates {(0 ,3) (-3 ,3)}; \end{axis} \end{tikzpicture}
- Why doesn't `enlargelimits` appear to do anything in this graph?by Matthew Bourque on June 17, 2025 at 8:07 pm
In the following MWE, I expected that the use of enlargelimits=true would enlarge the axis limits beyond the values which are computed from the function domain, and from the maximum and minimum function values computed for the graph. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat = newest} \begin{document} \begin{tikzpicture} \begin{axis}[ width = 5in, height = 3in, enlargelimits = true, axis x line = center, axis y line = center, xtick distance = 1, ytick distance = 0.5, grid = major, clip = false, domain = -6.28:6.28 ] \addplot[ <->, smooth, thick, blue, samples=101 ] {sin(deg(2*x+pi/4))}; \end{axis} \end{tikzpicture} \end{document} When I compile with pdfTeX (by way of latexmk, by way of VimTex), I get the following: The axes end exactly at the ends of my given domain, and at the max/min values computed for the function. I have also tried using enlargelimits = 0.2 with the same result. Why is that? How can I get the axes to enlarge a little bit in this plot?
- Labeling nodes of addplot in foreach loopby Ben on June 17, 2025 at 4:02 pm
I have the following minimal example where i would like to plot nodes with postions defined by the addplot enviroment, however within a foreach loop. \documentclass{standalone} \usepackage{pgfplots} \usepackage{tikz} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[axis equal, data cs=polar] %That works \foreach \a in {0.1,0.2,...,0.9}{ \addplot[data cs=polar, no marks] (180*\a,0.9) node[font=\small, inner sep = 1pt,black]{$\frac{\pi}{T}$};} %%That works not %\foreach \a in {0.1,0.2,...,0.9}{ %\addplot[data cs=polar, no marks] %(180*\a,0.9) node[font=\small, inner sep = 1pt,black]{$\frac{\a\pi}{T}$};} \end{axis} \end{tikzpicture} \end{document} I tried to use the \pgfmathprintnumber command as well as lets say some "unconventional" try with: %This gives some strange numbering as label \foreach \a in {0.1,0.2,...,0.9}{ \pgfmathparse{\a}\pgfmathresult \addplot[data cs=polar, no marks] (180*\a,0.9) node[font=\small, inner sep = 1pt,black]{$\frac{\pgfmathresult \pi}{T}$}; } However nothing works. I need the polar coordinates inside the plot area. It might be possible to use nodes that are postioned with "axis cs:" however in polar coordinates? Is someone out there how knows how to use a foreach variable as a label inside of node placed by addplot? Thanks a lot!
- Fill area between parametric curve and lineby Ricardo Freccero on June 16, 2025 at 10:04 pm
I've been trying for a while now to fill the area between a parametric curve and a line but had no success. I have the parabola y^2=2x-6 and the function y=x-1. I want to paint the area between them but it's not working. I think the issue is that I have to use a parametric form to plot the first curve. \documentclass{article} \usepackage{tikz, pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{fillbetween} \begin{document} \begin{tikzpicture} \begin{axis}[ clip=false, xlabel={$x$}, ylabel={$y$}, axis lines=center, axis on top=true, ] \addplot [black, thick, name path=A, domain=-3.5:4.5] ({x^2/2-3},{x}); \addplot [black, thick, name path=B, domain=-3.5:5.5] {x-1}; \addplot [blue!30] fill between [of=A and B, soft clip={domain=-3:5}]; \end{axis} \end{tikzpicture} \end{document} This is what I am getting Edit: I added the full code example
- Bug in pgfplots? "xticklabels" considers order in csv while "symbolic x coords" does notby nopx on May 19, 2025 at 11:47 am
For barplots: I found that xticklabels does considers the order in the csv files while symbolic x coords` does not. This leads to situations where incorrect data is displayed. That is the ticks do not appear for the correct data. In the below example it shows the value two for metric C, even though the value in the csv is three. What am I doing wrong? How to fix this? Here is a minimal example: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \iftrue % If true, the displayed data is wrong! The alternative is just two rows flipped, see below. \begin{filecontents*}{data.csv} ,methodA,methodB,methodC metricA,1,1,1 metricC,3,3,3 metricB,2,2,2 \end{filecontents*} \else \begin{filecontents*}{data.csv} ,methodA,methodB,methodC metricA,1,1,1 metricB,2,2,2 metricC,3,3,3 \end{filecontents*} \fi \begin{document} \pgfplotstableread[col sep = comma]{data.csv}\table \begin{tikzpicture} \begin{axis}[ ybar, symbolic x coords={metricA,metricB,metricC}, xticklabels={A,B,C}, xtick=data, ] \addplot [fill=red ] table [x index=0, y=methodA] {\table}; \addplot [fill=blue ] table [x index=0, y=methodB] {\table}; \addplot [fill=green] table [x index=0, y=methodC] {\table}; \end{axis} \end{tikzpicture} \end{document} If we extend the example to 6 different rows, it become even more confusing. \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{filecontents*}{data.csv} ,methodA,methodB,methodC A,1,1,1 B,2,2,2 D,4,4,4 E,5,5,5 F,6,6,6 C,3,3,3 \end{filecontents*} \begin{document} \pgfplotstableread[col sep = comma]{data.csv}\table \begin{tikzpicture} \begin{axis}[ ybar, symbolic x coords={A,B,C,D,E,F}, xtick=data, xticklabels={A,B,C,D,E,F}, ] \addplot [fill=red ] table [x index=0, y=methodA] {\table}; \addplot [fill=blue ] table [x index=0, y=methodB] {\table}; \addplot [fill=green] table [x index=0, y=methodC] {\table}; \end{axis} \end{tikzpicture} \end{document} The xticklabels seems to be completely confused about the labels. I don't see any pattern anymore ... Please, does anyone understand this?
- Consistent axis styling for multiple pgfplots positioned in a 3D tikzpictureby struct on September 28, 2024 at 6:18 am
I'm working on a tikzpicture that includes a main 3D plot and two additional 2D surface plots positioned within the 3D space. However, I've encountered an issue where the additional plots have differently scaled labels and thinner axis lines compared to the main plot, making them appear disproportionately smaller. Here's a simplified version of my current LaTeX code using pgfplots: \documentclass{standalone} \usepackage{pgfplots} \usetikzlibrary{3d,calc,positioning} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} % Main axis \begin{axis}[ name=mainaxis, enlargelimits=false, axis on top, axis equal image, axis lines = middle, xmin=0, xmax=8, ymin=-1, ymax=1, zmin=-1, zmax=10, xlabel=$x$, ylabel=$y$, zlabel=$z$, view={60}{30}, % xtick={0, 1, 3, 4}, ] % Coordinates for transformations \coordinate (O) at (axis cs:0,0,0); \coordinate (X) at (axis cs:1,0,0); \coordinate (Y) at (axis cs:0,1,0); \coordinate (Z) at (axis cs:0,0,1); % Positions where we want to place the surf plots \coordinate (P1) at (axis cs:1,0,0); \coordinate (P2) at (axis cs:3,0,0); \end{axis} % Transformation for surf plot at P1 \begin{scope}[shift={(P1)}, x={($(X)-(O)$)}, y={($(Y)-(O)$)}, z={($(Z)-(O)$)}, canvas is yz plane at x=0, transform shape] % Surf plot 1 \begin{axis}[ axis lines=middle, xlabel={$y$}, ylabel={$z$}, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, view={0}{90}, % scale=1, xtick={-1,0,1}, ytick={-1,0,1}, ] \addplot3[ surf, domain=-1:1, y domain=-1:1, samples=20, shader=flat, colormap/viridis, ] ({x},{y},{x^2 + y^2}); \end{axis} \end{scope} % Transformation for surf plot at P2 \begin{scope}[shift={(P2)}, x={($(X)-(O)$)}, y={($(Y)-(O)$)}, z={($(Z)-(O)$)}, canvas is yz plane at x=0, transform shape] % Surf plot 2 \begin{axis}[ axis lines=middle, xlabel={$y$}, ylabel={$z$}, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, view={0}{90}, scale=1, xtick={-1,0,1}, ytick={-1,0,1}, ] \addplot3[ surf, domain=-1:1, y domain=-1:1, samples=20, shader=flat, colormap/viridis, ] ({x},{y},{exp(-x^2 - y^2)}); \end{axis} \end{scope} \end{tikzpicture} \end{document} I aim to have all plots within the tikzpicture — the main 3D axis and the two additional 2D surface plots — share the same font sizes, line widths, tick styles, and overall dimensional consistency. How can I ensure that the additional pgfplots maintain the same typography and axis styling as the main plot?
- problem with combination of \foreach loops in pgfplotsby Excelsior on February 19, 2023 at 9:51 pm
I have a problem regarding the plot of multiple lines with a defined shift. There are several y-values and I don't want to copy every command, so I tried a for loop for the y index and the shift. With the current code I get a plot of all data which is shifted. \documentclass[border=5pt,tikz]{standalone} \usepackage{ pgfplots, pgfplotstable, filecontents } \begin{filecontents}[overwrite]{test.txt} 0 0.87 0.21 0.64 0.49 0.40 0.94 1 0.67 0.74 0.86 0.19 0.86 0.83 2 0.87 0.34 0.49 0.32 0.59 0.92 3 0.25 0.09 0.76 0.35 0.27 0.29 4 0.27 0.52 0.91 0.64 0.67 0.46 5 0.34 0.44 0.45 0.56 0.51 0.67 \end{filecontents} \def\xmin{0} \def\xmax{5} \def\ymin{0} \def\ymax{6} \def\shift{1} \begin{document} \begin{tikzpicture} \begin{axis}[ ymin=\ymin, ymax=\ymax, xmin=\xmin, xmax=\xmax, restrict y to domain=\xmin:\xmax, restrict y to domain=\ymin:\ymax, enlargelimits=0.1 ] \pgfplotsinvokeforeach{0,1,...,5}{ \foreach \i in {1,2,...,6}{ \addplot[ color=black, smooth, shift={(axis direction cs:0,#1*\shift)}, ] table[ x index=0, y index=\i, ]{test.txt}; } } \end{axis} \end{tikzpicture} \end{document} Is there a way to plot each line once and shifted to each other in a for loop? EDIT: For clearification: I want to plot each line individually with a certain shift.
- pgfplot x axis ticks aligned with a matrix beneath |by Lawliet on September 29, 2020 at 6:09 am
How can I make something like this as shown in the image using pgfplots in latex. I want the x-axis tick marks aligned with the other texts as shown in the image.
- Drawing a vector in tikz with a coordinate value of sqrt(3)by Dizzy on May 19, 2020 at 9:59 pm
I am trying to plot a vector with the coordinates (sqrt(3), 1). Latex won't accept the square root or 3^(1/2). Do I need to manually write in the decimal number every time I have a square root coordinate? \begin{tikzpicture} \begin{axis}[my style, xtick={-1,0,...,1}, ytick={-3,-2,...,3}, xmin=-2, xmax=2, ymin=-3, ymax=3 ] \draw[->, thick, blue](0,0) -- (-\sqrt(3),1)node[right] {$\vec z_1$}; \draw[->, thick, blue](0,0) -- (\sqrt(3),0)node[above,sloped] {$\vec z_2$}; \draw[->, thick, blue](0,0) -- (0,1)node[above,sloped] {$\vec z_1+ \vec z_2$}; \end{axis} \end{tikzpicture}
- "Logarithmic scale" for negative valuesby jazzpi on May 17, 2016 at 9:29 pm
I have the following MWE: \documentclass{standalone} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepackage{filecontents} \pgfplotsset{compat=1.12} \begin{filecontents}{data.dat} 4 -1e4 4 -1e3 4 -1e2 4 -10 4 -1 \end{filecontents} \begin{document} \begin{tikzpicture} \begin{axis}[ xmin=0, xmax=5 ] \addplot table {data.dat}; \end{axis} \end{tikzpicture} \end{document} This produces the following plot: Now I'd like to have ticks on the y axis at -1e0, -1e1, -1e2, -1e3 and -1e4 with even spacing. If my values are positive, I can achieve this by adding ymode=log to the axis options, but for negative values this just produces an error. So how can I produce a sort of logarithmic scale for negative values?