pgfplots
- Hyperlink does not scale in pgfplotsby Thomas on March 31, 2026 at 10:32 am
I have a figure drawn with pgfplots where I cite a reference in the legend. the issue I have is when I try to scale the whole figure, I noticed that the green hyper link for the reference is not scaled and inserted at the original place. Here is an ECM with on the one hand the figure in whole size, and on the other hand the figure scaled. \documentclass{article} \usepackage{biblatex} \usepackage{hyperref} \usepackage{pgfplots} \pgfplotsset{compat=1.5} \addbibresource{biblatex-examples.bib} \begin{document} \begin{tikzpicture} \begin{axis} \addplot[red, domain=-3e-3:3e-3, samples=51]{exp(-x^2 / (2e-3^2)) / (1e-3 * sqrt(2*pi))}; \addlegendentry{Text \cite{aksin}} \end{axis} \end{tikzpicture} % \begin{tikzpicture}[scale=0.9] \begin{axis} \addplot[red, domain=-3e-3:3e-3, samples=51]{exp(-x^2 / (2e-3^2)) / (1e-3 * sqrt(2*pi))}; \addlegendentry{Text \cite{aksin}} \end{axis} \end{tikzpicture} \printbibliography \end{document} On the linked export, we see that the second green boxed is not over the reference [1], but over the place it would have been if the figure were not scaled. Is it possible to set the correct location for this box ?
- Banded Multicolored Outlined With Copy Paste And Arbitrary Colors LuaLaTeXby keymasta on March 27, 2026 at 5:02 am
The spec: Any number of (arbitrary) color bands that we specify filling text Stroked outline Same positioning as normal text No extra text in the pdf stream (for copy-paste behavior you would expect) Ok and we're back to it! Previous versions have led here. None of the solutions so far have checked every box. We got as far as implementing 1-3. This is why this question is not a duplicate of the linked questions. None of the linked solutions implement 4 which is important to me. They all draw the text multiple times which unfortunately shows up in the pdf stream. I think that it is because for each \node the text is written again, This final version should have completely normal text-selection behavior, i.e, only ONE copy of the text. I have a new macro that attempts to use \accsupp to hide the extra copies of the text, but it does not work when I test it on Sumatra. I think that it does fix it for screen readers though which is why I kept it. It will however work when I try it in random other pdf readers like chrome. What I really want here is something that somehow only writes the text once, while looking exactly as this does, so that it should work in almost all pdf viewers. % !TEX TS-program = lualatex \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{pgfplots} \usepackage{accsupp} \usepackage{pdfrender} \newcommand{\TextShadeContour}[3]{% \begin{tikzpicture}[baseline] % Define reference node invisibly — needed for clip coordinates \node[anchor=base, inner xsep=0pt, inner ysep=.5pt, outer sep=0pt, opacity=0] (n) at (0,0) {#3}; % Scope contains all the cumulative clips from the loop \BeginAccSupp{method=plain,ActualText={}}% \begin{scope}% \foreach \c in {1,2,...,#1}{% \pgfplotscolormapaccess[1:#1]{\c}{ShadingColor}% \definecolor{colortemp}{rgb}{\pgfmathresult}% \pgfmathparse{1-(\c-1)/#1}% \clip let \p1=(n.south west), \p2=(n.north east), in% (n.south west) rectangle (\x2, \y1+\pgfmathresult*\y2-\pgfmathresult*\y1);% \node[colortemp, anchor=base, inner xsep=0pt, inner ysep=.5pt, outer sep=0pt]% {#3};% }% \end{scope}% \EndAccSupp{}% % Stroke is now outside the scope, so clipping is fully reset \node[anchor=base, inner xsep=0pt, inner ysep=.5pt, outer sep=0pt] at (0,0) {\textpdfrender{ TextRenderingMode=Stroke, LineWidth=0.5pt, StrokeColor=#2, MiterLimit=0.5, LineJoinStyle=Round }{#3}}; \end{tikzpicture}% }% \begin{document} \pgfplotsset{colormap={ShadingColor}{rgb255=(112,128,144) rgb255=(255,159,101)}}\TextShadeContour{3}{black}{13}\\ \end{document} The question is (maybe) how to use pdf literal commands to do it. My own knowledge of pdf internals is non-existent. Or it's about drawing the path of the text from within tikz vs. the actual text. Hopefully we don't have to use ghostscript or anything funky. Ideally this will just work in a way where we define the macro once and then use it. I know a pdf file can contain this. I can prove it with this typst MWE. If you run it and copy paste the whole line, it will do it just as we want (stuff and other stuff): #let multicolor_outline(content, colors) = { let grad = gradient.linear(..colors, angle:270deg) set text(stroke: 0.3pt, fill: grad.sharp(colors.len())) box(content) } #multicolor_outline([stuff], (red, orange, yellow, green, blue, purple)) and #multicolor_outline([other stuff], (purple, blue)) Previous discussion (which does not involve functional copy-pasting): Question 1 Question 2
- Trig label Issues on Graphby 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 pgfplotsby 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 axisby 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 surfaceby 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 [closed]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 pgfplotsby 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 Plotby 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 textwidthby 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 widthby 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 groupplotby 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 surfacesby 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/PGFPlotsby 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 graphby 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 pgfplotsby 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?
- 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}
- pgfplots / 2D contour filled plot from a csv fileby TheBeeTee on December 1, 2024 at 11:19 pm
Trying to plot a 2D colormap of my data like this: Here's my MWE with a sample of data. x,y are the coordinates. P is the value on which I want to base the shading. \documentclass[border=1 cm]{standalone} \usepackage{pgfplots} \begin{document} \begin{filecontents}{test.csv} x,y,P 0.6029680189,0.7383407645,2.3729000000 0.5323565117,0.6601831742,3.2726000000 0.4677196601,0.5882540709,4.0038000000 0.0946800948,0.6688882286,5.0510000000 0.1884371445,0.6355349568,5.0222000000 0.2792665104,0.5997515545,4.8900000000 0.3623180375,0.5641482523,4.6771000000 0.4853625211,0.1178246418,5.0150000000 0.4696592171,0.2354673908,4.9738000000 0.4525723312,0.3510530681,4.8490000000 0.4353225341,0.4584688067,4.6566000000 \end{filecontents} \begin{tikzpicture} \begin{axis}[ view = {0}{90}, colorbar, ] \addplot3[ contour filled={number = 20} ] table[x=x, y=y, z=P, col sep=comma]{test.csv}; \end{axis} \end{tikzpicture} \end{document} The code above was throwing: ERROR: shader=interp: got unsupported pdf shading type '0'. *****After more searching, I modified my MWE as follows. I don't get any errors, I just get an empty plot 🙁 \documentclass[border=1 cm]{standalone} \usepackage{pgfplots} \usepgfplotslibrary{patchplots} \begin{document} \begin{filecontents}{test.csv} x,y,P 0.6029680189,0.7383407645,2.3729000000 0.5323565117,0.6601831742,3.2726000000 0.4677196601,0.5882540709,4.0038000000 0.0946800948,0.6688882286,5.0510000000 0.1884371445,0.6355349568,5.0222000000 0.2792665104,0.5997515545,4.8900000000 0.3623180375,0.5641482523,4.6771000000 0.4853625211,0.1178246418,5.0150000000 0.4696592171,0.2354673908,4.9738000000 0.4525723312,0.3510530681,4.8490000000 0.4353225341,0.4584688067,4.6566000000 \end{filecontents} \begin{tikzpicture} \begin{axis}[ %view = {0}{90}, colorbar, ] \addplot[contour filled={number = 8,labels={false}}, mesh/rows=100,mesh/cols=100,mesh/check=false, patch type=bilinear, point meta=explicit, ] table [x=x, y=y, z=P, col sep=comma]{test.csv}; \end{axis} \end{tikzpicture} \end{document}
- How to add space between x axis labels and draw a vertical line after a set of IDs?by Student on November 21, 2024 at 8:13 pm
I'm trying to add space between x axis labels 10 Flows, 20 Flows, and 30 Flows and also properly draw a line after for every 1 to 8 IDs. Could someone help me with this problem? Code: % restructured data file: % - 'n' values are sorted ascending % - added column 'z' to know which data belong to which measurement % - added a dummy line at the end of each data set to produce an empty entry % for the separation of the blocks % - put all data in one file \begin{filecontents}{data.txt} z n pFA pFB 10 1 6 1 10 2 7 1 10 3 8 4 10 4 9 7 10 5 10 9 10 6 0 0 10 7 9 4 10 8 12 6 20 1 6 1 20 2 7 1 20 3 8 4 20 4 9 7 20 5 10 9 20 6 0 0 20 7 9 4 20 8 12 6 30 1 6 1 30 2 7 1 30 3 8 4 30 4 9 7 30 5 10 9 30 6 0 0 30 7 9 4 30 8 12 6 \end{filecontents} \documentclass[border=5pt]{standalone} \usepackage{pgfplots} \usetikzlibrary{patterns} \pgfplotsset{compat=1.3} \begin{document} \begin{tikzpicture} \begin{axis}[ footnotesize, % set the `width' of the plot to the maximum length ... width=\textwidth, % ... and use half this length for the `height' height=0.5\textwidth, ymin=0, ymax=100, %yticklabel=\pgfmathprintnumber{\tick}\,$\%$, % use `data' for the positioning of the `xticks' ... xtick=data, % ... and use table data for labeling the `xticks' xticklabels from table={data.txt}{n}, % add extra ticks "at the empty entries to add the vertical lines extra x ticks={8,16}, % this ticks shouldn't be labeled ... extra x tick labels={}, % ... but grid lines should be drawn without the tick lines extra x tick style={ grid=major, major tick length=0pt, }, xlabel={X Axis Label}, ylabel={Y Axis Label}, % because of the category labels, shift the `xlabel' a bit down xlabel style={ yshift=-4ex, }, legend pos=north west, legend entries={ {\color{black}{Algorithm A}}, {\color{red}{Algorithm B}}, }, area legend, % adjust `bar width' so it fits your needs ... bar width=10pt, % ... and with that you also have to adjust the x limits enlarge x limits=0.05, % set `clip mode' to `individual' so the category labels aren't clipped away clip mode=individual, ] % plot the "red" ybars \addplot [ ybar, draw=black, pattern color=black, pattern=dots, ] table [ % use just the `coordindex' as x coordinate, % the correct labeling is done with `xticklabels from table' x expr=\coordindex, y=pFA, ] {data.txt}; % plot the "blue" ybars \addplot [ ybar, draw=red, pattern color=red, pattern=north east lines, ] table [ x expr=\coordindex, y=pFB, ] {data.txt}; % add the category labels \begin{scope}[ % because the reference point will be the lower axis line the % labels have to be moved a bit more down to don't overlap with % the `xticklabels' every label/.append style={ label distance=2ex, }, ] \node [label=below:10 Flows] at (axis cs:4,\pgfkeysvalueof{/pgfplots/ymin}) {}; \node [label=below:20 Flows] at (axis cs:12,\pgfkeysvalueof{/pgfplots/ymin}) {}; \node [label=below:30 Flows] at (axis cs:20,\pgfkeysvalueof{/pgfplots/ymin}) {}; % \node [label=below:40 Flows] % at (axis cs:20,\pgfkeysvalueof{/pgfplots/ymin}) {}; %\node [label=below:50 Flows] % at (axis cs:26,\pgfkeysvalueof{/pgfplots/ymin}) {}; \end{scope} \end{axis} \end{tikzpicture} \end{document} Output:
- Tikz externalization with luacodeby pschulz on October 23, 2024 at 1:57 pm
I'm using luacode environments to assemble plot code for pgfplots. For many plots that works perfectly fine even with tikzexternalize. However, I have one plot where it does not work and the error message is cryptic. I reduced it to: \documentclass{article} \usepackage{pgfplots} \usepackage{luacode} \usetikzlibrary{external} \tikzexternalize \begin{document} %\tikzexternaldisable % doesn't compile with externalization, don't know why \begin{tikzpicture} \begin{axis} \begin{luacode*} local t = {} table.insert(t, "(0, 0)") table.insert(t, "(1, 1)") tex.print("\\addplot coordinates {") tex.print(table.concat(t)) tex.print("};") \end{luacode*} \end{axis} \end{tikzpicture} \end{document} So I used to get an error message like this: File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpicture I thought it might be related to a percent sign in the lua code (which I used for string.format), but I removed them. Now the strings are assembled a bit more manually. The problem persists, however, I don't get an error message any more. It just fails and it also does not create a main-figure0.log file, only the .md5 file. So what is going on?
- Cycling Line Colours with Pgfplot Cubic Spline Patchesby 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 fontby 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 functionby 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.
- legend style of bar plot pgfplotby 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 latexby 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.