• Trig label Issues on Graph
    by Nick B on March 13, 2026 at 1:07 pm

    I am trying to recreate this picture from the College Board. I am able to recreate the image with the x-axis labeled in fourths (pi). However, the original shows each label being 1/8 (pi). Each time I try to use specific xtick and xlabel, the spacing is incorrect. Is there an easier way I can do this? Here is my code: \documentclass[12pt]{article} \usepackage{fullpage,parskip,pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{arrows.meta} \begin{document} \begin{tikzpicture} \begin{axis}[ axis lines=middle, axis equal, clip=false, enlargelimits=false, xlabel={\(x\)}, ylabel={\(y\)}, title={Graph of \(f\)}, grid=major, grid style={black!75}, xmin=-2*pi/3,xmax=13*pi/6, ymin=-5,ymax=4, xtick={-0.75*pi, -0.5*pi, -0.25*pi, 0, 0.25*pi, 0.5*pi, 0.75*pi, pi, 1.25*pi, 1.5*pi, 1.75*pi, 2*pi, 2.25*pi}, xticklabels={, $-\frac{\pi}{2}$, , , , $\frac{\pi}{2}$, , $\pi$, , $\frac{3\pi}{2}$, , $2\pi$, }, ytick={-5, -4, -3, -2, -1, 0, 1, 2, 3, 4}, yticklabels={\(-5\), , \(-3\), , \(-1\), , \(1\), , \(3\)}, title style={ font=\Large, anchor=north, at={(rel axis cs: 0.5,0)}, yshift=-3mm, }, ticklabel style={fill=white}, axis line style={ thick,-{Triangle[length=3mm,width=2mm]},shorten >=-4mm,}, ticklabel style={fill=white, inner sep=1pt, font=\normalsize}, ] \addplot[samples=100,thick,domain=-2.09:6.54]{3*sin(deg(2*x-pi/2))}; \end{axis} \end{tikzpicture} \end{document} Any help would be appreciated. TYA

  • Error creating a graph using pgfplots
    by user516076 on March 10, 2026 at 3:37 am

    Here is the code: \documentclass[tikz,border=8pt]{standalone} \usepackage{pgfplots} \usetikzlibrary{arrows.meta} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ width=13.8cm, height=9.6cm, xmin=0, xmax=35, ymin=0, ymax=25, axis lines=left, axis line style={ -{Latex[length=4mm,width=3mm]}, line width=1pt, draw=black!65 }, xlabel={Time (s)}, ylabel={Speed (m/s)}, xlabel style={font=\Large, yshift=10pt}, ylabel style={font=\Large, yshift=-8pt}, xtick={0,10,20,30}, ytick={10,20}, tick style={black!65, line width=0.9pt}, tick label style={font=\Large, text=black!55}, major tick length=6pt, xmajorgrids=true, ymajorgrids=true, xminorgrids=true, yminorgrids=true, minor x tick num=4, minor y tick num=4, grid style={draw=cyan!28, line width=0.35pt}, major grid style={draw=cyan!65!blue, line width=0.8pt}, clip=false, enlargelimits=false ] \addplot[ color=red!75!black, line width=1.2pt ] coordinates { (0,0) (5,10) (15,10) (25,15) }; \node[font=\fontsize{22}{22}\selectfont, text=black] at (axis cs:2,5.8) {I}; \node[font=\fontsize{22}{22}\selectfont, text=black] at (axis cs:10.2,10.8) {II}; \node[font=\fontsize{22}{22}\selectfont, text=black] at (axis cs:19,13.4) {III}; \end{axis} \node[ anchor=west, font=\fontsize{26}{26}\selectfont, text=black!65 ] at ([xshift=-1cm,yshift=0.75cm]current bounding box.north west) {Graph A}; \end{tikzpicture} \end{document} and I expect it to be run using lualatex and will give me this image: What mistake did I make?

  • pgfplots rotation around axis
    by bbujeya on March 5, 2026 at 11:24 pm

    I'm trying to plot a 2D graph and have the students find the volume of solid of revolution. I can use pgfplots to do the bulk of it, but my question is: how do I show the arrows on the axis to demonstrate that we need to rotate around the x or y axes? \documentclass[tikz]{standalone} \usepackage{tikz} \usepackage{tkz-euclide} \usepackage{pgfplots}\pgfplotsset{compat=1.18} \usepackage{siunitx}\usepgfplotslibrary{fillbetween,statistics} \usetikzlibrary{calc,positioning,arrows.meta,patterns,patterns.meta,intersections,shapes.geometric,decorations,shapes.callouts,decorations.pathmorphing,decorations.pathreplacing}\usepackage{amssymb} \begin{document} \begin{tikzpicture} \begin{axis} [width=0.8\linewidth, xmin=-0.5,xmax=16, ymin=-0.2,ymax=5, axis lines=center,axis on top, xlabel=$x$,ylabel=$y$, xticklabels=\empty,yticklabels=\empty] \addplot[name path=cubic,thick,black,samples=50,smooth,domain=-0.5:16]{sqrt(x+1)}; \addplot[name path=line,thick,black,samples=50,smooth,domain=-0.5:16]{4}; \addplot[darkgray,opacity=0.5] fill between[of=cubic and line,soft clip={domain=0:15}]; \end{axis} \end{tikzpicture} \end{document} Thanks for your help/suggestions.

  • aerospace test questions [closed]
    by destine-lee destine-lee on March 5, 2026 at 3:13 pm

    \begin{array}{|c|} \hline \begin{minipage}{0.45\textwidth} \begin{center} \begin{tikzpicture}[scale=0.7] \draw (0,0) circle (1.5cm); \draw[thick, blue] (-1.5,0) -- (1.5,0); \fill[brown] (0,-1.5) arc (-90:-270:1.5cm and 0.6cm) -- cycle; \fill[blue] (0,1.5) arc (90:270:1.5cm and 0.6cm) -- cycle; \draw[yellow, very thick] (-0.3,0) -- (0.3,0); \draw[yellow, very thick] (0,-0.1) -- (0,0.1); \node at (0,0.6) {$10^\circ$}; \draw[yellow, very thick] (-0.1,0.6) -- (0.1,0.6); \node at (0,1.2) {$20^\circ$}; \draw[yellow, very thick] (-0.1,1.2) -- (0.1,1.2); \draw[<->, very thick] (2, -0.2) -- (2, 0.2); \node at (2.5, 0) {Bank}; \end{tikzpicture} \end{center} \end{minipage} \\ \hline \text{Attitude Indicator} \\ \hline \end{array}

  • Improving the visibility of a curve in a 3D PGFPlots surface
    by Octavius on March 2, 2026 at 4:50 pm

    In the left-hand figure, I would like to improve the visualization so that the red curve is more clearly visible. \documentclass[12pt,b5paper,twoside,openany]{book} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{amsmath,amssymb,amsfonts,amsthm} \usepackage{graphicx} \usepackage{xcolor} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \hypersetup{colorlinks=true,linkcolor=black,citecolor=black} \newtheorem{example}{Example} \setlength{\parindent}{0pt} \begin{document} \begin{example} Consider the function \[ f(x,y)=x^2+y^2, \] the point \[ c=(0,0), \] and the direction \[ u=(1,0). \] To study the variation of $f$ at $c$ in the direction $u$, we define the one-variable function \[ F(t)=f(c+tu). \] In this case, \[ c+tu=(t,0), \] and therefore \[ F(t)=f(t,0)=t^2. \] Thus, when we move away from $c$ in the direction $u$, the values of $f$ vary according to the quadratic function $F(t)=t^2$. The directional derivative of $f$ at $c$ in the direction $u$ is given by \[ f'(c;u)=F'(0). \] Since \[ F'(t)=2t, \] we obtain \[ f'(c;u)=F'(0)=0. \] \end{example} \bigskip \begin{center} \begin{tikzpicture} % --- SURFACE --- \begin{axis}[ at={(0,0)}, anchor=origin, view={120}{25}, axis lines=center, axis line style={->}, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, domain=-2:2, y domain=-2:2, samples=30, samples y=30, width=8cm, height=8cm ] % Surface z = x^2 + y^2 \addplot3[surf, opacity=0.4] {x^2+y^2}; % Curve corresponding to F(t) \addplot3[very thick, red, domain=0:1.2, samples=100] ({x},{0},{x^2}); \end{axis} % --- GRAPH OF F(t) --- \begin{axis}[ at={(7cm,0)}, anchor=origin, axis lines=middle, axis line style={->}, xlabel={$t$}, ylabel={$F(t)$}, domain=-1.5:1.5, samples=200, width=7cm, height=6cm ] \addplot[very thick, red] {x^2}; \node at (axis cs:1,1) [red, anchor=west] {$F(t)=t^2$}; \end{axis} \end{tikzpicture} \end{center} \end{document}

  • Creating Boxplot from precomputed value for each line in table
    by skanarr on February 26, 2026 at 4:53 pm

    I am using the box plot prepared method from here: Read boxplot prepared values from a table. My problem is the following: I have multiple rows in that csv and I want a box plot for each of these rows. How can I loop over all rows and create those? Added bonus: Some of my table columns are shorter than others, some have only enough data for 2 box plots, some have enough data for 10 box plots. % 1: extra for box plot, % 2: Identifier % 3: table, % 4: row \newcommandx{\TimeBoxPlot}[4][1={}]{ \addplot+[#2, #1, fill, boxplot prepared from table={ table=#3, row=#4, lower whisker= #2-time-min, lower quartile= #2-time-1, median= #2-time-med, upper quartile= #2-time-q3, upper whisker= #2-time-max, sample size = #2-sample-size, draw position = edge_count, }, boxplot prepared, ] coordinates {}; } % draw % Identifier % Table \newcommandx{\PlotPoint}[3][1={}]{ \pgfplotstablegetrowsof{#3} \pgfmathtruncatemacro{\numrows}{\pgfplotsretval-1} \pgfplotsinvokeforeach{0,...,\numrows}{ \TimeBoxPlot[#1]{#2}{#3}{##1} } } The identifier Mentioned is just a string-prefix for the columns in question and also a style I defined, so they are colored and drawn correctly. Though every Identifier has unbounded coords=discard set thats about the similarities. The implementation of \PlotPoint does not work. It is the macro that should go through all the lines (at least those with values).

  • Two 'Missing character: There is no ; (U+003B) in font nullfont!' warnings with pgfplots
    by Apoorv Potnis on February 25, 2026 at 5:13 pm

    I get two Missing character: There is no ; (U+003B) in font nullfont! warnings when I compile the below code with LuaLaTeX. I don't see any line numbers for the warnings in the .log file. I don't see any visual problem with the output though. \documentclass{article} \usepackage[newcmbb]{fontsetup} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usetikzlibrary{decorations.markings} \usetikzlibrary {arrows.meta,bending} \newcommand{\e}{\symrm{e}} \begin{document} \begin{figure}[h] \centering \begin{tikzpicture}[line cap=round] \begin{axis}[ samples=200, domain=0.24:4.5, xmin=0, xmax=5, ymin=-4.4, ymax=0.5, axis lines=middle, ticks=none, width=0.5\textwidth, xlabel={$r$}, ylabel={$V(r)$}, x axis line style={thick, -{>[bend]}}, y axis line style={thick, {<[bend]}-{>[bend]}}, y label style={anchor=south}, x label style={anchor=west}, legend style={ draw=none, at={(axis cs:2,-1.8)}, anchor=north west, row sep=10pt } ] \addplot[thick, red] {-exp(-x)/(x)}; \addplot[thick, blue, dashed] {-1/(x)}; \addlegendentry{$\displaystyle\frac{-\e^{-r}}{r}$}; \addlegendentry{$\displaystyle\frac{-1}{r}$}; \end{axis} \end{tikzpicture} \end{figure} \end{document} I saw another question with the same warning but there was a \tikz command in it which was causing issues. There is no \tikz command in my code. And I can't seem to find any stray semi-colons in the TikZ code either.

  • Slope Field Uniform Plot
    by Nick B on February 16, 2026 at 11:36 am

    I am trying to create slope fields based on several examples I have seen on here. My issue is that when I change my equation (the slope field I want to draw) my image does not appear to be square. I would like it uniform. The uniformity changes based on what function I plot. Is there a way to fix this? The image attached is from AP Classroom. Note the uniformity all the way around and how it is square, or flush. that is what I am looking for. \documentclass{standalone} \usepackage{pgfplots} \usetikzlibrary{arrows.meta} \pgfplotsset{compat=1.18} \begin{document} \centering \begin{tikzpicture} \begin{axis}[ view={0}{90}, axis lines=middle, axis equal image, width=10cm, xmin=-5.5, xmax=5.5, ymin=-5.5, ymax=5.5, xtick={-4,-2,2,4}, ytick={-4,-2,2,4}, xlabel=$x$, ylabel=$y$, axis line style={thick, -{Triangle[scale=1.2]}}, clip=false ] \addplot3[ thick, color=red, declare function={ f(\x,\y) = \x; norm(\x,\y) = sqrt(1 + (f(\x,\y))^2); }, quiver={ u={1/norm(x,y)}, v={f(x,y)/norm(x,y)}, scale arrows=0.4, every arrow/.append style={-} }, % -------------------------------- samples=15, domain=-4.2:4.2, domain y=-4.2:4.2 ] {0}; \end{axis} \end{tikzpicture} \end{document}

  • Table with pgfplots and title boxes across the entire textwidth
    by cis on February 13, 2026 at 10:16 am

    I want to use the entire \textwidth at a table, so I chose tabularx. The table contains plots (all the same size) and boxes with titles that contain varying amounts of text or lines. The "title boxes" should all be top-aligned, all have the same width and for each row (!) the same height. This means that the "title boxes" in row 1 have the same height, and those in row 3 also have the same height; but possibly a different height than in row 1. What's the best way to configure this? I've put the "title boxes" also into tabularx tables; but perhaps multirow would be more suitable here (?). I often have problems with overfull / underfull hbox warnings here. I don't know what the ideal solution for this. Note: I plan to disable the main table's rules later; I've set \setlength\arrayrulewidth{2pt} here to better visualize the dimensions. \documentclass[paper=a5]{scrarticle} \usepackage[margin=14mm, showframe]{geometry} \usepackage{tabularx} % \usepackage{multirow}% needed? \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{lipsum}% dummy text \newcommand\mytitle[1]{% {\begin{tabularx}{\linewidth}{|X|} \hline #1 \\ \hline \end{tabularx}} } \newcommand\myplot[1]{% \begin{tikzpicture}[baseline] \begin{axis}[width=\linewidth, height=30mm] \addplot[#1, mark=*]{x^4}; \end{axis} \end{tikzpicture}} \newcolumntype{Y}{% hspaces should be as small as possible @{\hspace{1.5pt}}X@{\hspace{1.5pt}}} \setlength\arrayrulewidth{2pt}% to see the effects \begin{document} \noindent\begin{tabularx}{\textwidth}{| Y | Y |} % Title 1 (row 1, column 1) ================== \mytitle{Title 1: \lipsum[1][1-2]} % Title 2 (row 1, column 2) ================== & \mytitle{Title 2: \lipsum[1][1]} \\ % Plot 1 (row 2, column 1) ================== \myplot{brown} % Plot 2 (row 2, column 2) ================== & \myplot{red} \\ \hline % Title 3 (row 3, column 1) ================== \mytitle{Title 3: \lipsum[1][2]} % Title 4 (row 3, column 2) ================== & \mytitle{Title 4: \lipsum[1][1-4]} \\ % Plot 3 (row 4, column 1) ================== \myplot{blue} % Plot 4 (row 4, column 2) ================== & \myplot{orange} \\ \end{tabularx} \end{document}

  • pgfplots: Adjust groupplot to text width
    by cis on February 11, 2026 at 9:28 am

    I have a 2×2 groupplot (where the first plot should be replaced by a title "Supertitle") with titles in boxes. These "title boxes" should all have the same width, and boxes in the same row should have the same height. I achieved this using \vphantom{} because I didn't find a better method. How can I configure the settings such that the entire groupplot has a width of \textwidth? And a horizontal space between the columns like \tabcolsep (or something similar)? Is there a elegant way to do this by package keys? (resizebox etc. would certainly work, but that would be less elegant.) Ideally, it should stay a groupplot. PS: I'm using DIN A5 format here, but that shouldn't matter if the keys are set correctly. \documentclass[paper=a5]{scrartcl} \usepackage[margin=14mm, showframe]{geometry} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \pgfplotsset{compat=1.18} \begin{document} \section{Plots with Titles and Supertitle} \pgfmathsetlengthmacro\plotwidth{0.5*\textwidth-\the\arraycolsep} \begin{tikzpicture}[font=\footnotesize] \begin{groupplot}[ % Grouupplot settings ================== group style={ group size=2 by 2, % 2 columns, 2 rows vertical sep=25mm, horizontal sep=15mm, }, % Styles applied to all subplots ============== width=\plotwidth, height=30mm, % Title Styles ========================== title style={% at={(0,1)}, xshift=-3ex, align=left, anchor=south west, inner xsep=2pt, draw, fill=none, text width=0.925*\pgfkeysvalueof{/pgfplots/width}, },% ] % Title (Row 1, Col 1) \nextgroupplot[ % I don't know how to get this box to the same height without this trick: title={\vphantom{Plot 0} \\ \vphantom{000} \\ \vphantom{000}}, title style={name=super}, hide axis, ] \addplot[draw=none, samples={0}]{x}; % Plot 0 (Row 1, Col 2) \nextgroupplot[title={Title 0 \\ 000 \\ 000}] \addplot{x}; % Plot 1 (Row 2, Col 1) \nextgroupplot[title={Title 1 \\ 2-111 \\ 3-111 \\ 4-111}] \addplot{x^2}; % Plot 2 (Row 2, Col 2) \nextgroupplot[title={Title 2 \\ 2-222 \\ 3-222 \\ \vphantom{4-111}}] \addplot{x^3}; \end{groupplot} %% Supertitle \node[font=\bfseries\Large] at (super){Supertitle}; \node[anchor=north west, draw=none, align=left,] at (super.south west){ Some notes \\ below Supertitle}; \draw[cyan, very thick, |-|] (group c1r2.west) -- +(\plotwidth,0) node[midway, below, fill=yellow]{plotwidth =\plotwidth}; %% This gives a 'Overfull \hbox ' warning ================== \draw[red, thick, |-|, ] ([yshift=5mm]group c1r2.west) -- +(2*\plotwidth,0) node[midway, above, fill=yellow]{2*plotwidth =\plotwidth}; \end{tikzpicture} \end{document}

  • pgfplots: align legend entries at a groupplot
    by cis on February 9, 2026 at 2:09 pm

    I have a groupplot where I want to use the legend as the title in the \nextgroupplots. And then I have a "Supertitel" that I would like to put in place of the first groupplot. How do I set it such that the text, like the small box, is aligned to the top edge? \documentclass[margin=5pt, varwidth]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{groupplots} \usetikzlibrary{patterns} \begin{document} \begin{tikzpicture}[font=\footnotesize, mypattern/.style={% postaction={pattern=north east lines}, },% ] \begin{groupplot}[ group style={% group size=2 by 3, vertical sep=15mm, },% height=30mm,width=55mm, group/every plot/.style={%% ybar=0pt, bar width=1, bar shift=0pt, xmin=-0.5,% to see the bar at x=0 correctly ymin=0, xtick=data, },%% end of group/every plot/.style %% every axis plot/.style={ fill=lightgray, area legend,% legend as title 1/2 }, legend style={% legend as title 2/2 at={(0,1)}, yshift=6pt, anchor=south west, draw=none, fill=none, inner sep=0pt, cells={anchor=north, align=left},% PROBLEM HERE ..... },% ] \nextgroupplot[hide axis=true, title={Supertitle}, title style={at={(0.5,0.5)}, anchor=center, yshift=-6pt,% kill pgfplots's default draw=none, font=\bfseries\Large} ] \addplot[draw=none, fill=none]{x};% to avoid warning; don't know how to make this else \nextgroupplot[] \addplot[samples at={0,...,8}, forget plot]{x}; \addplot[mypattern, samples at={3,...,6}]{x}; \addlegendentry{plot 0: \\ plot good, \\ legend bad :(} \end{groupplot} \end{tikzpicture} \end{document}

  • Using xint in pgfplots (example: binomial distribution)
    by cis on February 9, 2026 at 9:26 am

    If I have a function with xint, say % \bdceval{<n>}{<p>}{<k>} \xintNewFloatExpr{\bdeval}[3]{% %B(n,p,k) = binomial(n,k)*p^k*(1-p)^(n-k) % formula binomial(#1,#3)*#2^#3*(1-#2)^(#1-#3)} this works well in text (e.g. \bdeval{13}{0.4}{5}); but how can I use that in pgfplots? In the following MWE I have drawn an example using pgfplots; the same curve should result with xint. \documentclass[margin=5pt, varwidth]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{xintexpr} %\usepackage{xinttools}% needed? % \bdceval{<n>}{<p>}{<k>} \xintNewFloatExpr{\bdeval}[3]{% %B(n,p,k) = binomial(n,k)*p^k*(1-p)^(n-k) % formula binomial(#1,#3)*#2^#3*(1-#2)^(#1-#3)} % \bd[<digits, default: 4>]{<n>}{<p>}{<k>} \NewExpandableDocumentCommand{\bd}{O{4} mmm}{% %\xinteval{round(#2+#3+#4,2)}% for tests \xintRound{#1}{\bdeval{#2}{#3}{#4}}% rounded bd-values } \begin{document} \section{xint in Text (works)} $B(13,0.4,5) =\bdeval{13}{0.4}{5} \approx \bd{13}{0.4}{5}$ \par $B(1000,0.4,50) =\bdeval{1000}{0.4}{50} \approx \bd{1000}{0.4}{50}$ \section{xint in pgfplots (works not)} \begin{tikzpicture}[font=\footnotesize, declare function={ binom(\n,\p,\k)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);% works %xbinom(\n,\p,\k)=\bdeval{\n}{\p}{\k};% works not } ] \begin{axis}[ title={\texttt{xint} in pgfplots?}, title style={fill=blue!25}, xlabel={$k$}, ylabel={$P(X=k)$}, yticklabel style={ /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=2 }, xtick=data, variable=\k, only marks, ] \addplot+[samples at={0,...,13}] {binom(13, 0.4, k)}; % DOES NOT WORK %\addplot [samples at={0,...,13}] {\bd{13}{0.4}{\k} }; \end{axis} \end{tikzpicture} \end{document}

  • pgfplots: axis-enlargement at a ybar plot (example: binomial distribution)
    by cis on February 8, 2026 at 4:34 pm

    I wanted to adapt this nice solution for my purposes. • I want to extend the x- and y-axes a bit. But, when I set enlarge y limits={upper, abs=0.125} it creates a strange gap (ymin=0 is no longer respected, and restrict y to domain=0:1 seems to have no effect). • Secondly, what's the best way to configure it so that bars with very small y-values ​​are also visible here? • Unfortunately, I saw this too late: I would also like to eliminate this x-gap between the first bar and the y-axis! \documentclass[margin=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture}[font=\footnotesize, declare function={ binom(\n,\p,\k)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k); } ] \begin{axis}[%y=8mm, no effect ymin=0, xmin=0, axis lines=left, axis line style={-latex}, xlabel={$k$}, ylabel={$P(X=k)$}, x label style={at={(axis description cs:1,0)}, anchor=south east, inner xsep=0pt }, y label style={at={(axis description cs:0,1)}, rotate = -90, anchor=north west, inner ysep=0pt, }, yticklabel style={ /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=2 }, ybar=0pt, bar width=1, bar shift=0pt, samples at={0,...,13}, variable=\k, enlarge x limits={upper, abs=0.785}, enlarge y limits={upper, abs=0.125}, %restrict y to domain=0:1,% no effect.... ] \addplot [fill=gray!25] {binom(13, 0.4, k)}; %\addplot [fill=orange, samples at={0,...,4}] {binom(12,0.4,k)}; %\addplot [fill=cyan, samples at={7}] {binom(12,0.4,k)}; \end{axis} \end{tikzpicture} \end{document}

  • Finding and displaying the intersection points of two surfaces
    by SH.Madadpour on February 6, 2026 at 10:23 am

    How can I display the intersection of the following two surfaces in LaTeX? I have used the following codes as a default but I am not getting acceptable output. Is it possible to create a form to find its intersection points in LaTeX? Thanks a lot. \documentclass[border=3.14mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \begin{document} \begin{tikzpicture} \begin{axis}[domain=0.01:30,xlabel=$x$] \addplot3[surf,domain={0:1},color=green]{x^3+y^3}; \addplot3[surf,domain={0:1},color=red]{(x*(1-y^2)^(.5)+y*(1-x^2)^(.5))^3}; \end{axis} \end{tikzpicture} \end{document}

  • Adding Value Labels to the Centre of Stacked Bars in TikZ/PGFPlots
    by Fernando on February 5, 2026 at 5:11 pm

    I was looking at this post (pgfplots stacked bar plot: distance to axis, padding between bars) and was wondering how to add the value of each stacked segment directly in the middle of its corresponding bar. For example, for “Something else”, if the value associated with “Transfer” is 5, how can that 5 be placed in the centre of the red segment? The MWE: \documentclass{article} \usepackage{xcolor} \usepackage{tikz} \usepackage{pgfplots} \definecolor{transfertoserver}{HTML}{D7191C} \definecolor{database}{HTML}{FDAE61} \definecolor{transfertoclient}{HTML}{ABDDA4} \definecolor{rendering}{HTML}{2B83BA} \begin{document} \begin{figure} \centering \begin{tikzpicture} \begin{axis}[ xbar stacked, legend style={ legend columns=4, at={(xticklabel cs:0.5)}, anchor=north, draw=none }, ytick=data, axis y line*=none, axis x line*=bottom, tick label style={font=\footnotesize}, legend style={font=\footnotesize}, label style={font=\footnotesize}, xtick={0,5,10,15,20,25}, width=.8\textwidth, bar width=6mm, xlabel={Time in Seconds}, yticklabels={Database Optimizations, Reference Timing, Something Else}, xmin=0, xmax=25, area legend, y=8mm, enlarge y limits={abs=0.625}, ] \addplot[transfertoserver,fill=transfertoserver] coordinates % Transfer {(0.38,0) (0.38,1) (5,2)}; \addplot[database,fill=database] coordinates % Database {(2.4,0) (9.66,1)(5,2)}; \addplot[transfertoclient,fill=transfertoclient] coordinates % Transfer {(0.23,0) (0.23,1)(5,2)}; \addplot[rendering,fill=rendering] coordinates % Rendering {(14.66,0) (14.66,1)(5,2)}; \legend{Transfer,Database,Transfer,Rendering} \end{axis} \end{tikzpicture} \caption{Performance Benefit by Database Optimizations} \label{fig:performance:database} \end{figure} \end{document}

  • Problem with the position of a graph (pgfplots)
    by Octavius on February 5, 2026 at 12:36 am

    in the following code and in the attached image, the graph becomes misaligned. Could you please give me an idea on how to fix it? \documentclass{article} \usepackage{graphicx} % Required for inserting images \newcommand{\ocultar}[1]{} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{pdfpages} \usepackage{hyperref} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage[utf8]{inputenc} \usepackage[spanish]{babel} \usetikzlibrary{angles, quotes} \usepackage{fancyhdr} \usepackage{graphicx} \usepackage{array} \begin{document} \begin{center} \begin{tabular}{>{\centering}m{5cm} >{\centering}m{5cm} >{\centering}m{5cm}} % CRECIENTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[red, thick] {x+1}; \end{axis} \end{tikzpicture} & % DECRECIENTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[blue, thick] {-x+3}; \end{axis} \end{tikzpicture} & % CONSTANTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[black, thick] {3}; \end{axis} \end{tikzpicture} \\[2mm] \fbox{\begin{minipage}{4.5cm} \centering \textbf{Creciente.}\\ En este caso su pendiente\\ es \textcolor{red}{\textbf{POSITIVA}.} \end{minipage}} & \fbox{\begin{minipage}{4.5cm} \centering \textbf{Decreciente.}\\ En este caso su pendiente\\ es \textcolor{blue}{\textbf{NEGATIVA}.} \end{minipage}} & \fbox{\begin{minipage}{4.5cm} \centering \textbf{Constante.}\\ En este caso su pendiente\\ es \textbf{CERO}. \end{minipage}} \end{tabular} \end{center} \end{document}

  • Unexpected “ccc” labels appearing in a pgfplots graph
    by Octavius on February 4, 2026 at 8:51 pm

    I have the following LaTeX code, and in the middle plot (the decreasing function) I cannot remove the letters “ccc” that appear on the graph. Does anyone have a suggestion on how to fix this? \documentclass{article} \usepackage{graphicx} % Required for inserting images \newcommand{\ocultar}[1]{} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{pdfpages} \usepackage{hyperref} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage[utf8]{inputenc} \usepackage[spanish]{babel} \usetikzlibrary{angles, quotes} \begin{document} \begin{center} \begin{tabular}{>{\centering}m{5cm} >{\centering}m{5cm} >{\centering}m{5cm}} % CRECIENTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[red, thick] {x+1}; \end{axis} \end{tikzpicture} & % DECRECIENTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[blue, thick] {-x+3}; \end{axis} \end{tikzpicture} & % CONSTANTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[black, thick] {3}; \end{axis} \end{tikzpicture} \end{document}

  • Exceeded TeX capacity when running hilatex with scrartcl and pgfplots
    by Alexander Voigt on February 4, 2026 at 4:56 pm

    I want to generate a test.hnt file from the following test.tex file: \documentclass{scrartcl} % article works \usepackage{pgfplots} % removing this works \begin{document} Hello World! \end{document} When I run hilatex test.tex I get the following error message about exceeded TeX capacity: ! TeX capacity exceeded, sorry [hash size=45000]. \pgfkeyslet ...ter \let \csname pgfk@#1\endcsname #2 l.4831 } The test.log file contains the following information about the issue: ! TeX capacity exceeded, sorry [hash size=45000]. \pgfkeyslet ...ter \let \csname pgfk@#1\endcsname #2 l.4831 } If you really absolutely need more capacity, you can ask a wizard to enlarge me. Here is how much of TeX's memory you used: 22130 strings out of 475903 562725 string characters out of 5796992 1256262 words of memory out of 5000001 45000 multiletter control sequences out of 45000 559137 words of font info for 37 fonts, out of 8000000 for 255 475 hyphenation exceptions out of 8191 108i,7n,107p,10900b,609s stack positions out of 5000i,500n,10000p,2000000b,100000s This issue does not occur when I remove pgfplots. (However, this package is required in my project.) How can I avoid this issue?

  • Incorrect polar coordinate positions and changing color of marks
    by humanoferth on February 2, 2026 at 7:02 pm

    I've been trying to plot coordinates using the polar library of PGFplots, but the plot is just... wrong? Like the points are just not at the right position, and I'm not too sure what I'm missing. I'm pretty sure it may have something to do with using radians instead of degrees, but when I use radians to graph, they turn out fine. I would really prefer not to use degrees, but if it's the only solution, then I'll do the conversions. I'm also struggling to figure out how to change the actual infill color of the nodes. I've been referencing section 4.7.1, and in the code below I use fill, draw, and color, but the infill remains the same. Any help would be greatly appreciated. 🙂 \documentclass{report} \usepackage{amsmath} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{polar} \begin{document} \[ \begin{array}{c|c} \text{Name}&(r,\theta)\\\hline A&(1,\dfrac{\pi}{3})\\ B&(2,\dfrac{3\pi}{4})\\ C&(3,\dfrac{7\pi}{6})\\ D&(-1,\dfrac{2\pi}{3})\\ \end{array}\implies\begin{tikzpicture}[baseline=(current bounding box.center)] \begin{polaraxis}[xticklabels={,0,$\frac{\pi}{6}$,$\frac{\pi}{3}$,$\frac{\pi}{2}$,$\frac{2\pi}{3}$,$\frac{5\pi}{6}$,$\pi$,$\frac{7\pi}{6}$,$\frac{4\pi}{3}$,$\frac{3\pi}{2}$,$\frac{5\pi}{3}$,$\frac{11\pi}{6}$}] \addplot+ [trig format plots=rad, data cs=polarrad,only marks,color=black, mark color=black,draw=black,fill=black,] coordinates {(1,pi/3)(2,3*pi/4)(3,7*pi/6)(-1,2*pi/3)}; \end{polaraxis} \end{tikzpicture} \] \end{document}

  • Mutliple plots using raw gnuplot within pgfplots
    by jak123 on February 2, 2026 at 1:36 pm

    Why does this produce a broken .gnuplot code when compiled? I'm trying to plot the gamma function as segments. \documentclass[tikz]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel={$x$}, ylabel={$\Gamma(x)$}, axis lines={ middle, }, every axis x label/.append style={ font=\footnotesize, at={(axis cs: 0,1)} }, every axis y label/.append style={ font=\footnotesize, at={(ticklabel cs: 1.05, 0)} }, xmin=-4, xmax=4, ymin=-15, ymax=15, restrict y to domain=-15:15, ] \addplot gnuplot [ raw gnuplot, samples=555, smooth, id=myplot ] { plot \ [-4:-3] gamma(x) notitle, \ [-3:-2] gamma(x) notitle, \ [-2:-1] gamma(x) notitle, \ [-1: 0] gamma(x) notitle, \ [ 0: 4] gamma(x) notitle }; \end{axis} \end{tikzpicture} \end{document} Output: set format "%.7e";; plot \ [-4:-3] gamma(x) notitle, \ [-3:-2] gamma(x) notitle, \ [-2:-1] gamma(x) notitle, \ [-1: 0] gamma(x) notitle, \ [ 0: 4] gamma(x) notitle

  • Using radians in polaraxis environment (PGFplots)
    by humanoferth on January 30, 2026 at 6:28 pm

    I've been trying to graph some polar functions using PGFplots and I've been refrencing this section of the manual: https://tikz.dev/pgfplots/libs-polar where in 5.10.2 it says that I should be using datacs=polarrad to convert to polar coordinates, but the graphs have come out wrong, so I've been using degrees to get accurate graphs, though I would rather be using radians. Any ideas of what I'm doing wrong / what I can do to fix it? I've put a couple of bare-bones examples of what I mean below. \documentclass{report} \usepackage{amsmath} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{polar} \begin{document} \[\begin{tikzpicture}[baseline={(0,3)}] \begin{polaraxis} \addplot+ [domain=0:360] {cos(x)}; \end{polaraxis} \end{tikzpicture} \begin{tikzpicture}[baseline={(0,3)}] \begin{polaraxis} \addplot+ [domain=0:2*pi,data cs=polarrad] {cos(x)}; \end{polaraxis} \end{tikzpicture}\] \[\begin{tikzpicture}[baseline={(0,3)}] \begin{polaraxis} \addplot+ [domain=0:360] {cos(x)*sin(x)}; \end{polaraxis} \end{tikzpicture} \begin{tikzpicture}[baseline={(0,3)}] \begin{polaraxis} \addplot+ [domain=0:2*pi,data cs=polarrad] {cos(x)*sin(x)}; \end{polaraxis} \end{tikzpicture}\] \end{document} Also a bit of a side note, but is there an easy way to switch the axes from degrees to radians besides manually changing each one individually via the xticklabel command? Thanks!

  • pgfplots 3d schoolbook style (grid/tick marks)
    by Sammy on May 16, 2025 at 3:48 pm

    I'm trying to recreate the look of a 3D coordinate system as used in German schoolbooks. Below, I've included a minimal working example (MWE). The code that handles the grid and tick marks is quite lengthy, and my implementation isn’t very robust when it comes to making changes. Is there a simpler and more reliable way to achieve the desired result using pgfplots, particularly regarding the style and placement of tick marks and the background grid? I considered modifying the tick mark style, but as far as I can tell, there's no built-in option for this. (Avoid multiple tick marks in 3D tikz plot). I looked through the source code of pgfplots for a code piece I could patch, but I wasn't able to understand what's going on. It seems in an earlier version of pgfplots there was a bug that kind of "implemented" the tick mark style I'm looking for: Uniform appearance of tick marks in 3d pgfplot? Fix: https://github.com/pgf-tikz/pgfplots/commit/47a07927c46ecbdcd8a982c90c922bc4925e828b Is there a way to access the tick positions directly directly? Is there an easier option to have the tick marks always have length 0.1 inch regardless what value the ytick distance is? In the target style, the orientation of the axes will always be the same as shown in the example, and the distance between two grid lines should always be 5 mm. I’d like to retain this consistent layout while being able to freely adjust other parameters in the plot. Any other suggestions or improvements are very welcome. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \newcommand{\unitvectorx}{(\pgfkeysvalueof{/pgfplots/minor x tick num} + 1)*0.5/\pgfkeysvalueof{/pgfplots/xtick distance}} \newcommand{\unitvectory}{(\pgfkeysvalueof{/pgfplots/minor y tick num} + 1)*0.5/\pgfkeysvalueof{/pgfplots/ytick distance}} \newcommand{\unitvectorz}{(\pgfkeysvalueof{/pgfplots/minor z tick num} + 1)*0.5/\pgfkeysvalueof{/pgfplots/ztick distance}} \pgfplotsset{ 3d_style/.style={ axis lines = middle, tick style = transparent, major tick length = 0.1in, minor tick num = 1, xtick distance = 1, ytick distance = 1, ztick distance = 1, xlabel = $x_1$, ylabel = $x_2$, zlabel = $x_3$, x = {(-.5cm*\unitvectorx,-.5cm*\unitvectorx)}, y = {(1cm*\unitvectory,0)}, z = {(0,1cm*\unitvectorz)}, set layers = standard, execute at end axis = {\pgfmathsetmacro{\xenlarge}{(\pgfkeysvalueof{/pgfplots/xmax} - \pgfkeysvalueof{/pgfplots/xmin}) * \pgfkeysvalueof{/pgfplots/enlarge x limits})} \pgfmathsetmacro{\yenlarge}{(\pgfkeysvalueof{/pgfplots/ymax} - \pgfkeysvalueof{/pgfplots/ymin}) * \pgfkeysvalueof{/pgfplots/enlarge y limits})} \pgfmathsetmacro{\zenlarge}{(\pgfkeysvalueof{/pgfplots/zmax} - \pgfkeysvalueof{/pgfplots/zmin}) * \pgfkeysvalueof{/pgfplots/enlarge z limits})} \pgfmathsetmacro{\xmin}{\pgfkeysvalueof{/pgfplots/xmin} - \xenlarge} \pgfmathsetmacro{\ymin}{\pgfkeysvalueof{/pgfplots/ymin} - \yenlarge} \pgfmathsetmacro{\zmin}{\pgfkeysvalueof{/pgfplots/zmin} - \zenlarge} \pgfmathsetmacro{\xmax}{\pgfkeysvalueof{/pgfplots/xmax} + \xenlarge} \pgfmathsetmacro{\ymax}{\pgfkeysvalueof{/pgfplots/ymax} + \yenlarge} \pgfmathsetmacro{\zmax}{\pgfkeysvalueof{/pgfplots/zmax} + \zenlarge} \pgfmathsetmacro{\ygriddist}{\pgfkeysvalueof{/pgfplots/ytick distance} / (\pgfkeysvalueof{/pgfplots/minor y tick num} + 1)} \pgfmathsetmacro{\zgriddist}{\pgfkeysvalueof{/pgfplots/ztick distance} / (\pgfkeysvalueof{/pgfplots/minor z tick num} + 1)} \pgfmathsetmacro{\ygridmin}{ceil(\ymin / \ygriddist) * \ygriddist} \pgfmathsetmacro{\zgridmin}{ceil(\zmin / \zgriddist) * \zgriddist} \pgfmathsetmacro{\ygridnext}{\ygridmin + \ygriddist} \pgfmathsetmacro{\zgridnext}{\zgridmin + \zgriddist} \pgfmathsetmacro{\ygridmax}{floor(\ymax / \ygriddist) * \ygriddist} \pgfmathsetmacro{\zgridmax}{floor(\zmax / \zgriddist) * \zgriddist} \pgfmathsetmacro{\xtickmin}{ceil(\xmin / \pgfkeysvalueof{/pgfplots/xtick distance}) * \pgfkeysvalueof{/pgfplots/xtick distance}} \pgfmathsetmacro{\ytickmin}{ceil(\ymin / \pgfkeysvalueof{/pgfplots/ytick distance}) * \pgfkeysvalueof{/pgfplots/ytick distance}} \pgfmathsetmacro{\ztickmin}{ceil(\zmin / \pgfkeysvalueof{/pgfplots/ztick distance}) * \pgfkeysvalueof{/pgfplots/ztick distance}} \pgfmathsetmacro{\xticknext}{\xtickmin + \pgfkeysvalueof{/pgfplots/xtick distance}} \pgfmathsetmacro{\yticknext}{\ytickmin + \pgfkeysvalueof{/pgfplots/ytick distance}} \pgfmathsetmacro{\zticknext}{\ztickmin + \pgfkeysvalueof{/pgfplots/ztick distance}} \pgfmathsetmacro{\xtickmax}{floor(\xmax / \pgfkeysvalueof{/pgfplots/xtick distance}) * \pgfkeysvalueof{/pgfplots/xtick distance}} \pgfmathsetmacro{\ytickmax}{floor(\ymax / \pgfkeysvalueof{/pgfplots/ytick distance}) * \pgfkeysvalueof{/pgfplots/ytick distance}} \pgfmathsetmacro{\ztickmax}{floor(\zmax / \pgfkeysvalueof{/pgfplots/ztick distance}) * \pgfkeysvalueof{/pgfplots/ztick distance}} \pgfmathsetmacro{\tickylength}{\pgfkeysvalueof{/pgfplots/major tick length}/1cm*0.5/\pgfkeysvalueof{/pgfplots/ytick distance}} \pgfmathsetmacro{\tickzlength}{\pgfkeysvalueof{/pgfplots/major tick length}/1cm*0.5/\pgfkeysvalueof{/pgfplots/ztick distance}} \pgfplotsonlayer{axis background} \draw[gray!50] \foreach \y in {\ygridmin,\ygridnext,...,\ygridmax}{(0,\y,\zmin) -- (0,\y,\zmax)}; \draw[gray!50] \foreach \z in {\zgridmin,\zgridnext,...,\zgridmax}{(0,\ymin,\z) -- (0,\ymax,\z)}; \endpgfplotsonlayer \pgfplotsonlayer{axis ticks} \draw \foreach \x in {\xtickmin,\xticknext,...,\xtickmax}{(\x,0,-\tickzlength) -- (\x,0,\tickzlength)}; \draw \foreach \y in {\ytickmin,\yticknext,...,\ytickmax}{(0,\y,-\tickzlength) -- (0,\y,\tickzlength)}; \draw \foreach \z in {\ztickmin,\zticknext,...,\ztickmax}{(0,-\tickylength,\z) -- (0,\tickylength,\z)}; \endpgfplotsonlayer } } } \begin{document} \begin{tikzpicture} \begin{axis}[ 3d_style, xmin=-9.2, xmax=9.2, ymin=-5.2, ymax=5.2, zmin=-5.2, zmax=5.2, ] \end{axis} \end{tikzpicture} \end{document}

  • Cycling Line Colours with Pgfplot Cubic Spline Patches
    by Freddie Witherden on September 5, 2024 at 6:30 pm

    Consider the following snippet: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{colorbrewer, patchplots} \begin{document} \begin{tikzpicture} \begin{axis}[cycle list/Set2] \addplot+[patch, patch type=cubic spline, point meta=none, red] coordinates { (-1,-1) (1,1) (-1/3,{(-1/3)^3}) (1/3,{(1/3)^3}) }; \end{axis} \end{tikzpicture} \end{document} which is based off the cubic spline patch example in the PGFPLOTS manual. As expected it produces a red curve. However, I am having trouble changing the colour to be one from a set. For example swapping red for index of colormap=2 of Set2 causes the line to revert to black. What is the correct means of applying a uniform colour from a colour map to all of the patches?

  • pgf import in LaTeX not working due to matplotlib axes font
    by L_physics on May 20, 2024 at 1:12 pm

    I was plotting as usual and then after saving one of my plots as a pgf and then compiling LaTeX it didn't work anymore. As far as I'm aware of, I didn't change anything it just so happen to top working. The code I'm using to make an example plot is the following: import matplotlib . pyplot as plt import numpy as np from pathlib import Path import matplotlib .cm as cm import tikzplotlib import matplotlib as mpl mpl.rcParams['mathtext.fontset'] = 'cm' # Latex font mpl.rcParams['font.family'] = 'serif' mpl.rcParams['font.serif'] = ['cmr10'] mpl.rcParams['axes.formatter.use_mathtext'] = True # Erzeuge eine Liste von x-Werten x = np.linspace(-5, 10, 100) a= [2,8,8,2] b=[2,2,8,2] U_1=2 U_2=8 I_1=2 I_2=8 # Berechne die entsprechenden y-Werte für die Funktion y = x y = x # Plotte die Funktion plt.plot(x, y) plt.plot(a,b, color = 'crimson', marker='', linestyle='dashed') plt.plot(U_1,I_1, color = 'green', marker='x', linestyle='',label='$(U_{1}, I_{1})$', markersize=14) plt.plot(U_2,I_2, color = 'orange', marker='x', linestyle='',label='$(U_{1}, I_{2})$', markersize=14) plt.plot(U_2,I_1, color = 'purple', marker='x', linestyle='',label='$(U_{2}, I_{2})$', markersize=14) # Beschriftungen für die Achsen hinzufügen plt.xlabel('$I$ / arbitrary units') plt.ylabel('$U$ / arbitrary units') # Titel für den Plot hinzufügen plt.title('Beispiel Fit') plt.legend(loc='upper left') # Grid hinzufügen plt.grid(True) # Den Plot anzeigen plt.savefig('example.pgf', format='pgf', bbox_inches='tight', pad_inches = 0) plt.show() I tried multiple things and I'm pretty sure that the problem is in the commands mpl.rcParams['font.serif'] = ['cmr10'] mpl.rcParams['axes.formatter.use_mathtext'] = True Sure I can commen them out but then (more bovious for other plots) the axes will be in a weird font and if I have a different, let's say logarithmic scaling, it wont look like 10^{-21} like in latex and the font is different as well. The error codes in Latex which I'm getting are ! Undefined control sequence. <recently read> \mathdefault l.109 ...\catcode`\%=\active\def%{\%}$\mathdefault {\ensuremath{-}4}$}}% The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. ! Undefined control sequence. <recently read> \mathdefault l.147 ...\catcode`\%=\active\def%{\%}$\mathdefault {\ensuremath{-}2}$}}% The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. ! Undefined control sequence. <recently read> \mathdefault l.185 ...\catcode`\%=\active\def%{\%}$\mathdefault {0}$}}% The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. ! Undefined control sequence. <recently read> \mathdefault l.223 ...\catcode`\%=\active\def%{\%}$\mathdefault {2}$}}% The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. ... I also posted this question here https://stackoverflow.com/q/78504075/2777074

  • pgfplot: Fill between while including decoration function
    by otiuuaugusto on January 11, 2023 at 10:43 pm

    I am trying to fill between area for a specific plot within a groupplot environment. I have already tried to follow the pgfplot manual which is pretty clear with respect to the name path abd \path[] ... but I just always get the same weird outcome (see picture below). Since I was using the x-axis as the delimitation for the fill between, I started trying to use something else to check if something would change. Below is my MWE: \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{fillbetween} \usepackage{textcomp} \pgfplotsset{compat=1.18} \usepackage{siunitx} \usepackage{tikzscale} \usetikzlibrary{pgfplots.groupplots} \usetikzlibrary{decorations.markings} \begin{document} \begin{tikzpicture} \begin{groupplot}[ group style={ group name = 4L_keywaveform_sim_S6currentstress, group size = 1 by 1, vertical sep = 15pt }, clip=true, enlargelimits=false, height = 0.75\textwidth, width = \textwidth, axis x line = bottom, axis y line = left, xlabel={$t$}, xlabel style={align=right, anchor=west, xshift=5.8cm, yshift=0.6cm}, x axis line style={shorten >=-15pt}, xmin=0, xmax=12.5, ymajorgrids=true, yminorgrids = true, xmajorgrids=true, grid style={dashed}, set layers,cell picture=true, ] \nextgroupplot[ymin=0, %Position colunm 1 by row 1 ymax=15, ytick align = outside, ytick pos = left, axis y line = left, ylabel = {$y$}, legend columns=1, ] \addplot[color=blue, name path global = teste1, domain=0:15, postaction={decorate},% ------ decoration={markings, % ------ mark=between positions 0.05 and 1 step (1/10)*\pgfdecoratedpathlength with {\arrow{Latex}}, }, ] {x}; \label{test}; \addlegendentry{$x$}; \addplot[color=red, name path global = teste2, domain=0:15] {-3 + x^2}; \path[name path global = teste3] (axis cs:0,5) -- (axis cs:12.5,5); \addplot[blue, fill=blue, fill opacity=0.4] fill between[of= teste1 and teste3]; \end{groupplot} \end{tikzpicture} \end{document} The MWE consists of only 1by1 groupplot for simplificativo purpose. But the issue persists for n by m groupplot. EDIT/UPDATE: By investigating a bit further, it seems that the decoration arguments are messing up with the fill between. I do not know the reason for that, though. Thanks,

  • Creating a "data-dump" table procedurally?
    by Justin Jung on March 28, 2022 at 3:08 am

    I have a ~50 sample dataset I'd like to put into a table. Because there's only one variable to display, a single column chart looks ridiculous and wastes a lot of space. Is there a way I can get it to fill the page with data (i.e., wrap the data horizontally and vertically)? I'm imagining something like this image, with the header row taking up the full width, and the data cells in between. I tried using pgfplotstable, but I couldn't really wrap my head around it.

  • How to get set the precision of the PGFPLOTS?
    by user266771 on March 20, 2022 at 1:56 pm

    I want to plot the a strange function which is the 'InterpolatingPolynomial' of the tanh(x): (40*x*tanh(1/2))/11-(698249*x^3*tanh(1/2))/87318+(2517135701*x^5*tanh(1/2))/392931000-(8990599279*x^7*tanh(1/2))/3536379000+(666523661*x^9*tanh(1/2))/1178793000-(87882491*x^11*tanh(1/2))/1178793000+(2616454*x^13*tanh(1/2))/442047375-(40708*x^15*tanh(1/2))/147349125+(1024*x^17*tanh(1/2))/147349125-(32*x^19*tanh(1/2))/442047375-(15*x*tanh(1))/11+(1650809*x^3*tanh(1))/232848-(7656977201*x^5*tanh(1))/1047816000+(15347344853*x^7*tanh(1))/4715172000-(269158459*x^9*tanh(1))/349272000+(82887751*x^11*tanh(1))/785862000-(2527141*x^13*tanh(1))/294698250+(6658*x^15*tanh(1))/16372125-(508*x^17*tanh(1))/49116375+(16*x^19*tanh(1))/147349125+(80*x*tanh(3/2))/143-(1827209*x^3*tanh(3/2))/567567+(11431199701*x^5*tanh(3/2))/2554051500-(5986965079*x^7*tanh(3/2))/2554051500+(39926233*x^9*tanh(3/2))/65488500-(17379821*x^11*tanh(3/2))/196465500+(4771412*x^13*tanh(3/2))/638512875-(77416*x^15*tanh(3/2))/212837625+(6016*x^17*tanh(3/2))/638512875-(64*x^19*tanh(3/2))/638512875-(30*x*tanh(2))/143+(1888949*x^3*tanh(2))/1513512-(3240137519*x^5*tanh(2))/1702701000+(17611561711*x^7*tanh(2))/15324309000-(130451323*x^9*tanh(2))/392931000+(1695689*x^11*tanh(2))/32744250-(8810596*x^13*tanh(2))/1915538625+(148112*x^15*tanh(2))/638512875-(1312*x^17*tanh(2))/212837625+(128*x^19*tanh(2))/1915538625+(48*x*tanh(5/2))/715-(9587629*x^3*tanh(5/2))/23648625+(109639993*x^5*tanh(5/2))/170270100-(3194891431*x^7*tanh(5/2))/7662154500+(5165621*x^9*tanh(5/2))/39293100-(1447093*x^11*tanh(5/2))/65488500+(796564*x^13*tanh(5/2))/383107725-(69928*x^15*tanh(5/2))/638512875+(128*x^17*tanh(5/2))/42567525-(64*x^19*tanh(5/2))/1915538625-(5*x*tanh(3))/286+(1933049*x^3*tanh(3))/18162144-(14119093201*x^5*tanh(3))/81729648000+(4749355073*x^7*tanh(3))/40864824000-(81091903*x^9*tanh(3))/2095632000+(10896041*x^11*tanh(3))/1571724000-(1767109*x^13*tanh(3))/2554051500+(8147*x^15*tanh(3))/212837625-(698*x^17*tanh(3))/638512875+(8*x^19*tanh(3))/638512875+(60*x*tanh(7/2))/17017-(5663*x^3*tanh(7/2))/262548+(2464771*x^5*tanh(7/2))/69498000-(106900847*x^7*tanh(7/2))/4378374000+(44989*x^9*tanh(7/2))/5346000-(25313*x^11*tanh(7/2))/16038000+(45439*x^13*tanh(7/2))/273648375-(14*x^15*tanh(7/2))/1447875+(64*x^17*tanh(7/2))/221524875-(16*x^19*tanh(7/2))/4652022375-(5*x*tanh(4))/9724+(487121*x^3*tanh(4))/154378224-(53447083*x^5*tanh(4))/10216206000+(336140003*x^7*tanh(4))/91945854000-(3039931*x^9*tanh(4))/2357586000+(147211*x^11*tanh(4))/589396500-(157426*x^13*tanh(4))/5746615875+(3208*x^15*tanh(4))/1915538625-(1712*x^17*tanh(4))/32564156625+(64*x^19*tanh(4))/97692469875+(20*x*tanh(9/2))/415701-(11419*x^3*tanh(9/2))/38594556+(5040143*x^5*tanh(9/2))/10216206000-(3558293*x^7*tanh(9/2))/10216206000+(32699*x^9*tanh(9/2))/261954000-(19447*x^11*tanh(9/2))/785862000+(1789*x^13*tanh(9/2))/638512875-(38*x^15*tanh(9/2))/212837625+(64*x^17*tanh(9/2))/10854718875-(16*x^19*tanh(9/2))/206239658625-(x*tanh(5))/461890+(514639*x^3*tanh(5))/38594556000-(364919*x^5*tanh(5))/16345929600+(5839219*x^7*tanh(5))/367783416000-(21713*x^9*tanh(5))/3772137600+(5473*x^11*tanh(5))/4715172000-(619*x^13*tanh(5))/4597292700+(17*x^15*tanh(5))/1915538625-(2*x^17*tanh(5))/6512831325+(8*x^19*tanh(5))/1856156927625 It's very scary lmao but, I try to trans it into 0.9979114*x-0.3195393*x^3+0.1056912*x^5-0.02658724*x^7+0.004606668*x^9-0.0005249908*x^11+0.00003808077*x^13-0.000001675943*x^15+0.0000000405108*x^17-0.000000000410371*x^19 and put it in 'PGFPLOTS': \documentclass{ctexart}\usepackage{tikz}\usepackage{pgfplots,xfp}\begin{figure}[h] \centering \pgfplotsset{width=12cm,height=7cm} \begin{tikzpicture} \begin{axis}[ title={The Runge phenomenon of the function $\tanh x$}, xlabel={$x$}, ylabel={$y$}, axis x line=center, axis y line=center, every inner x axis line/.append style={->}, every inner y axis line/.append style={->}, xmin=-6,xmax=6 ] \addplot[domain=-5:5, samples=800, color=gray,smooth,]{0.9979114*x-0.3195393*x^3+0.1056912*x^5-0.02658724*x^7+0.004606668*x^9-0.0005249908*x^11+0.00003808077*x^13-0.000001675943*x^15+0.0000000405108*x^17-0.000000000410371*x^19}; \addplot[domain=-5.2:5.2,color=black, samples=400,very thick]{tanh(x)}; \end{axis} \end{tikzpicture} \end{figure} and get the figure and this annoying 'saw' if I use the scary one: \documentclass{ctexart}\usepackage{tikz}\usepackage{pgfplots,xfp}\begin{figure}[h] \centering \pgfplotsset{width=12cm,height=7cm} \begin{tikzpicture} \begin{axis}[ title={The Runge phenomenon of the function $\tanh x$}, xlabel={$x$},legend pos = north west, ylabel={$y$}, axis x line=center, axis y line=center, every inner x axis line/.append style={->}, every inner y axis line/.append style={->}, xmin=-6,xmax=6 ] \addplot[domain=-5:5, samples=800, color=gray,smooth,]{(40*x*tanh(1/2))/11-(698249*x^3*tanh(1/2))/87318+(2517135701*x^5*tanh(1/2))/392931000-(8990599279*x^7*tanh(1/2))/3536379000+(666523661*x^9*tanh(1/2))/1178793000-(87882491*x^11*tanh(1/2))/1178793000+(2616454*x^13*tanh(1/2))/442047375-(40708*x^15*tanh(1/2))/147349125+(1024*x^17*tanh(1/2))/147349125-(32*x^19*tanh(1/2))/442047375-(15*x*tanh(1))/11+(1650809*x^3*tanh(1))/232848-(7656977201*x^5*tanh(1))/1047816000+(15347344853*x^7*tanh(1))/4715172000-(269158459*x^9*tanh(1))/349272000+(82887751*x^11*tanh(1))/785862000-(2527141*x^13*tanh(1))/294698250+(6658*x^15*tanh(1))/16372125-(508*x^17*tanh(1))/49116375+(16*x^19*tanh(1))/147349125+(80*x*tanh(3/2))/143-(1827209*x^3*tanh(3/2))/567567+(11431199701*x^5*tanh(3/2))/2554051500-(5986965079*x^7*tanh(3/2))/2554051500+(39926233*x^9*tanh(3/2))/65488500-(17379821*x^11*tanh(3/2))/196465500+(4771412*x^13*tanh(3/2))/638512875-(77416*x^15*tanh(3/2))/212837625+(6016*x^17*tanh(3/2))/638512875-(64*x^19*tanh(3/2))/638512875-(30*x*tanh(2))/143+(1888949*x^3*tanh(2))/1513512-(3240137519*x^5*tanh(2))/1702701000+(17611561711*x^7*tanh(2))/15324309000-(130451323*x^9*tanh(2))/392931000+(1695689*x^11*tanh(2))/32744250-(8810596*x^13*tanh(2))/1915538625+(148112*x^15*tanh(2))/638512875-(1312*x^17*tanh(2))/212837625+(128*x^19*tanh(2))/1915538625+(48*x*tanh(5/2))/715-(9587629*x^3*tanh(5/2))/23648625+(109639993*x^5*tanh(5/2))/170270100-(3194891431*x^7*tanh(5/2))/7662154500+(5165621*x^9*tanh(5/2))/39293100-(1447093*x^11*tanh(5/2))/65488500+(796564*x^13*tanh(5/2))/383107725-(69928*x^15*tanh(5/2))/638512875+(128*x^17*tanh(5/2))/42567525-(64*x^19*tanh(5/2))/1915538625-(5*x*tanh(3))/286+(1933049*x^3*tanh(3))/18162144-(14119093201*x^5*tanh(3))/81729648000+(4749355073*x^7*tanh(3))/40864824000-(81091903*x^9*tanh(3))/2095632000+(10896041*x^11*tanh(3))/1571724000-(1767109*x^13*tanh(3))/2554051500+(8147*x^15*tanh(3))/212837625-(698*x^17*tanh(3))/638512875+(8*x^19*tanh(3))/638512875+(60*x*tanh(7/2))/17017-(5663*x^3*tanh(7/2))/262548+(2464771*x^5*tanh(7/2))/69498000-(106900847*x^7*tanh(7/2))/4378374000+(44989*x^9*tanh(7/2))/5346000-(25313*x^11*tanh(7/2))/16038000+(45439*x^13*tanh(7/2))/273648375-(14*x^15*tanh(7/2))/1447875+(64*x^17*tanh(7/2))/221524875-(16*x^19*tanh(7/2))/4652022375-(5*x*tanh(4))/9724+(487121*x^3*tanh(4))/154378224-(53447083*x^5*tanh(4))/10216206000+(336140003*x^7*tanh(4))/91945854000-(3039931*x^9*tanh(4))/2357586000+(147211*x^11*tanh(4))/589396500-(157426*x^13*tanh(4))/5746615875+(3208*x^15*tanh(4))/1915538625-(1712*x^17*tanh(4))/32564156625+(64*x^19*tanh(4))/97692469875+(20*x*tanh(9/2))/415701-(11419*x^3*tanh(9/2))/38594556+(5040143*x^5*tanh(9/2))/10216206000-(3558293*x^7*tanh(9/2))/10216206000+(32699*x^9*tanh(9/2))/261954000-(19447*x^11*tanh(9/2))/785862000+(1789*x^13*tanh(9/2))/638512875-(38*x^15*tanh(9/2))/212837625+(64*x^17*tanh(9/2))/10854718875-(16*x^19*tanh(9/2))/206239658625-(x*tanh(5))/461890+(514639*x^3*tanh(5))/38594556000-(364919*x^5*tanh(5))/16345929600+(5839219*x^7*tanh(5))/367783416000-(21713*x^9*tanh(5))/3772137600+(5473*x^11*tanh(5))/4715172000-(619*x^13*tanh(5))/4597292700+(17*x^15*tanh(5))/1915538625-(2*x^17*tanh(5))/6512831325+(8*x^19*tanh(5))/1856156927625}; \addplot[domain=-5.2:5.2,color=black, samples=400,very thick]{tanh(x)}; \end{axis} \end{tikzpicture}\end{figure} I get I thaught that it's the precision of PGFPLOTS made this, and how to fix them?

  • Is there a way to ignore a plot for the axis limit calculation in pgfplots?
    by Benedikt Bauer on February 21, 2020 at 9:32 pm

    I have two data files, one with measurement values (data.dat) and a second one with model data that describes how the values in data.dat are expected to behave (model.dat). Values in data.dat are added every now and then as they occur. The values in model.dat span over a far greater x range than the measurement values in data.dat. Currently I limit the x axis to fit the data.dat values "manually" by setting an appropriate xmax value. However, it would be nice if the x axis range would be calculated automatically according to the data.dat values either by ignoring the model.dat values for the axis range calculation or telling pgfplots to calculate the axis range based on a certain plot or data file. Is there such functionality in pgfplots? Comment: Define different ranges for different data sets when plotting from a file or table might be loosely related or could be the way towards a workaround. \begin{filecontents}{model.dat} x y 0 1 1 0.8 2 0.75 3 0.72 4 0.7 5 0.69 \end{filecontents} \begin{filecontents}{data.dat} x y 0 0.99 1 0.81 2 0.74 3 0.70 \end{filecontents} \documentclass{minimal} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[xmax=4] \addplot table[x=x,y=y] {data.dat}; \addplot table[x=x,y=y] {model.dat}; \end{axis} \end{tikzpicture} \end{document}

  • legend style of bar plot pgfplot
    by user1935724 on November 12, 2019 at 12:25 am

    I've copied an example bar plot from the manual. I had a little trouble to tweak the style of the legend. Here is what I've got. \begin{tikzpicture} \begin{axis}[ x tick label style={/pgf/number format/1000 sep=}, ylabel=\emph{Population}, xlabel=\emph{years}, enlargelimits=0.15, % legend style={at={(0.5,-0.15)}, % anchor=north,legend columns=-1}, ybar, bar width=9pt, ] \addplot [black!100!white,fill=black!100!white] coordinates { % \addplot [black!20!black,fill=black!50!white] coordinates { (1930,50e6) (1940,33e6) (1950,40e6) (1960,50e6) (1970,70e6) }; \addplot [black!30!white,fill=black!30!white] coordinates { (1930,38e6) (1940,42e6) (1950,43e6) (1960,45e6) (1970,65e6) }; \legend{Far,Near} \end{axis} \end{tikzpicture} The plot look likes this However, I want the legend to be

  • How to draw slope fields with all the possible solution curves in latex
    by MaoYiyi on October 16, 2013 at 3:17 am

    Sorry, I have no code to submit, mostly because I have no idea how to do this. I want to type up my homework (I can do the homework by hand) and I am looking for a simple method that I can use repetitively on different equations; without having to code each equation; to make/produce/draw the slope field of that equation. Currently, I have typed up the rest of my homework with latex, but have no good example from the internet to follow. I want to put the slope fields for both $\frac{\mathrm{d}y}{\mathrm{d}x}=2x$ and $\frac{\mathrm{d}y}{\mathrm{d}x}=x\sqrt{x}$ into my homework. My system is Fedora 19. Any suggestions? ps. sorry if this is a poor quality question. I just used the suggested tags.