• Plot the cubic root function and its inverse
    by Dimitrios ANAGNOSTOU on April 18, 2025 at 12:06 pm

    I want to plot the cubic root function and its inverse. I use the following code: \documentclass[border=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \begin{axis}[ width=0.8\textwidth, height=0.8\textwidth, axis equal, grid=both, xmin=-2, xmax=5, ymin=-2, ymax=5, axis lines=middle, xlabel={$x$}, ylabel={$y$}, legend pos=south east, legend style={draw=none}, ticklabel style={font=\scriptsize}, label style={font=\scriptsize}, legend style={font=\scriptsize} ] % Add unit vectors \draw[thick,-latex] (axis cs:0,0) -- (axis cs:0,1) node[midway, right, font=\scriptsize] {$\mathbf{j}$}; \draw[thick,-latex] (axis cs:0,0) -- (axis cs:1,0) node[midway, below, font=\scriptsize] {$\mathbf{i}$}; % Plot x^3 \addplot[ blue, domain=-2.5:2.5, samples=100, thick ] {x^3}; \addlegendentry{$x\mapsto x^3$} % Plot cubique(x) \addplot[ red, domain=0:2.5^3, samples=1000, thick ] {x^(1/3)}; \addlegendentry{$x\mapsto \sqrt[3]{x}=x^{1/3}$} % Plot y = x \addplot[ green, domain=-2.5:4.5, samples=100, dashed, thick ] {x}; \addlegendentry{$x\mapsto x$} % Plot cubique(x) pour les valeurs négatives \addplot[ red, domain=(-(2.5^3)):0, samples=2000, thick ] {-(-x)^(1/3)}; % Add the point (1.5, 3.3750) \node[circle,fill,inner sep=1.pt,label={[label distance=-1mm, font=\scriptsize] above right:{$(1.5, 3.375)$}}] at (axis cs:1.5,{1.5^3}) {}; % Add the point (3.3750, 1.5) \node[circle,fill,inner sep=1pt,label={[label distance=-1mm, font=\scriptsize] below :{$(3.375, 1.5)$}}] at (axis cs:3.375,1.5) {}; % Définition des points \coordinate (A) at (axis cs:1.5,3.375); \coordinate (B) at (axis cs:3.375,1.5); \coordinate (M) at (axis cs:{(1.5+3.375)/2},{(3.375+1.5)/2}); % Milieu de A et B % Traits pointillés entre A--M et M--B \draw[dashed] (A) -- (M); \draw[dashed] (M) -- (B); % Point M avec annotation \node[circle,fill,inner sep=1pt, label={[label distance=-1mm, font=\tiny] below:{$\left(\frac{1.5+3.375}{2}, \frac{3.375+1.5}{2}\right)$}}] at (M) {}; % Origine \node[label={[label distance=-1mm, font=\scriptsize] below left:{$O$}}] at (axis cs:0,0) {}; % Marque d'angle droit \draw ($(M)!2mm!(A)$) -- ++ ($($(M)!2mm!(axis cs:0,0)$)-(M)$) -- ($(M)!2mm!(axis cs:0,0)$); \end{axis} \end{tikzpicture} \end{document} I cannot understand the gap below: Any ideas to fix it (or even better to simplify the code)? Thanks!

  • PGFPlots: Coordinate Arithmetric, curious behavior when zero vector is not added
    by Grass on April 18, 2025 at 7:00 am

    The other day, I was absolutely puzzled by why my code didn't work. Turns out, adding the zero vector +(0,0) magically fixed everything. I'm curious to find out why, though unfortunately I have had no luck finding answers on the web so far. Could someone here explain this? \documentclass[tikz]{standalone} \usetikzlibrary{calc} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} % Nice, expected behavior \begin{tikzpicture} \begin{axis}[ xmin=-5, xmax=5, ymin=-5, ymax=5, ] \draw[thick,blue] (0,0) -- ($(0,0)+2*(axis direction cs:-1,1)$); \end{axis} \end{tikzpicture} % Inexplicable yeeting `to infinity' \begin{tikzpicture} \begin{axis}[ xmin=-5, xmax=5, ymin=-5, ymax=5, ] \draw[thick,blue] (0,0) -- ($2*(axis direction cs:-1,1)$); \end{axis} \end{tikzpicture} \end{document} The first tikzpicture produces while the second one produces

  • TikZ: Floating xbars not starting at 0
    by Ludger on April 18, 2025 at 4:55 am

    I've just spent the past ~hour digging through the pgfplots documentation, and Stackoverflow but have not been able to find an example of a floating bar chart, where individual bars do not start at 0. What I am looking to accomplish is something like this: I.e. if the specific bar finishes at e.g. 0.7, I want it to start at a value greater than 0. Here is a MWE, in which the bars presently start at 0, but where I would want them to start at e.g. 0.05. Thank you so much for all the help! \documentclass[crop,tikz]{standalone} \usepackage{pgfplots} \usepackage{tikz} \pgfplotsset{compat=1.17} \begin{document} \begin{tikzpicture} \begin{axis}[symbolic y coords={cat1, cat2}] \addplot [xbar] coordinates {(0.3,cat1)}; \addplot [xbar] coordinates {(0.7,cat2)}; \end{axis} \end{tikzpicture} \end{document} (The number of y-axis labels can be ignored)

  • \pgfplotsforeachungrouped to define different colors
    by Angelo Aliano Filho on April 17, 2025 at 2:38 pm

    I have the MWE: \documentclass[border=2mm,tikz]{standalone} \usepackage[T1]{fontenc} \usepackage{helvet} \renewcommand{\familydefault}{\sfdefault} \usepackage[italic]{mathastext} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel=$x$, ylabel=$y$, width=10cm, height=8cm, axis lines = middle, xmin=-8, xmax=8, ymin=-1, ymax=200, legend style = { at={(0,1)}, anchor=north west, font=\scriptsize, legend columns=1, legend cell align=left, %draw=none }, ] \addplot[color=red,domain=-4:2] {exp(x)}; \addlegendentry{$\exp x$} \edef\serie{0} \edef\contador{0} \pgfplotsforeachungrouped \n in {0,1,...,5}{ \edef\serie{ \serie+pow(x,\n)/factorial(\n) } \edef\contador{ \pgfmathparse{\contador+1} } \addplot[blue!\fpeval{100*\contador/6}!red,no marks,samples=100,smooth,line width=1pt]{\serie}; \addlegendentryexpanded{ordem $\the\numexpr\n$} } \end{axis} \end{tikzpicture} \end{document} I want to plot the Taylor Polinomials of exp(x). I would like to draw in different colors of blue and red. I have used \pgfplotsforeachungrouped structure and I need to weight the blue and red in each iteration (using the variable \contador and calculate the number 100*\contador/6 using \fpeval{...}. This works very wel when I work in tikz, not in PGFplots). I have defined the macro \contador but this not work. How can I define the 100% of blue when n=0 and 100% of red when n=5 in my plots?

  • How to use `tkz-euclide` with `pgfplots`
    by Mr.Hedge on April 17, 2025 at 12:56 am

    Is there any way to make tkz-euclide compatible with pgfplots axis environment? Here is my code example where I want to add mark using \tkzMarkSegment but more often I want to find some line intersections or draw circles. Interestingly, simple \tkzLabelPoint works. \documentclass[tikz, margin=3mm]{standalone} \usetikzlibrary{ arrows.meta, positioning, } \usepackage{tkz-euclide} \usepackage{pgfplots} \usepackage[dvipsnames,table]{xcolor} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ xmin=-2.9, xmax=15.9, ymin=-3.9, ymax=15.9, xtick distance=1, ytick distance=1, xticklabels=\empty, yticklabels=\empty, extra y ticks={1}, extra y tick labels={$1$}, extra x ticks={1}, extra x tick labels={$1$}, axis lines=middle, axis line style={-Stealth}, xlabel={$X$}, ylabel={$Y$}, xlabel style={at={(ticklabel* cs:1)}, anchor=north east, font=\footnotesize}, ylabel style={at={(ticklabel* cs:1)}, anchor=north west, font=\footnotesize}, grid=both, grid style={dotted, gray!50}, set layers, clip mode=individual, axis equal image=true, % scale only axis, % unit vector ratio=2,1, ] \coordinate (A) at (axis cs:2,8); \coordinate (B) at (axis cs:10,2); \coordinate (S) at (axis cs:6,5); \draw[thick, black] (A)--(B); \draw[black, fill=black] (A) circle(1.5pt) (B) circle(1.5pt); \tkzLabelPoint[above left](A){$A$} \tkzLabelPoint[below right](B){$B$} \addplot [name path = A,domain=-2:15, samples=2, thick, color=Red] {4/3*x-3} node[pos=0.8, sloped, above, font=\footnotesize]{$y=\frac{4}{3}x-3$}; \draw[Green, fill=Green] (S) circle(1.5pt); \tkzMarkSegment[mark=|, pos=0.5](S,B) \end{axis} \end{tikzpicture} \end{document}

  • How can I plot some datapoint stored in a CSV file in the Tensorboard style
    by galoischan on April 16, 2025 at 2:11 pm

    I stored some of the loss function curve as a CSV file and want to plot them in the way that Tensorboard plot them. But I have difficulty to realise two thing: plot the smoothened version of the curve show the entries with nan on the plot(maybe show each of the entries with nan as a red small triangle) THANK YOU A LOT This is the plot I get with the code I posted below: This is the plot how Tensorboard display the data(the original data is a little dimmer):(It is not a must to show the smoothened curve with the unsmoothened curve side by side, I just want a smoothened curve and a plot without skipping nan value at the end) the CSV file: run-.-tag-advg.csv some part of the CSV is posted here: Wall time,Step,Value 1727044803.2813585,55500,0.00949437078088522 1727045020.3863645,55550,0.010245434008538723 1727045240.331363,55600,0.009481625631451607 1727045463.5903947,55650,0.008838667534291744 1727045682.8413923,55700,0.008703619241714478 1727045899.1863914,55750,0.009342261590063572 1727046342.809394,55850,0.009162072092294693 1727046561.1233923,55900,0.00917676743119955 1727046779.3624206,55950,0.009618055075407028 1727046996.754392,56000,0.00986748468130827 1727047220.450394,56050,0.009403795003890991 1727047437.2354002,56100,0.008110546506941319 1727047656.1613934,56150,0.00843835063278675 1727048314.9193914,56300,0.008264702744781971 1727048533.4113946,56350,0.009781372733414173 1727048749.7403913,56400,0.009383087046444416 1727048969.5113904,56450,nan 1727049193.2183917,56500,nan 1727049412.4563947,56550,nan 1727049630.3143904,56600,nan 1727049851.3293905,56650,nan 1727050075.366392,56700,nan 1727050294.0353918,56750,nan The code is here: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{tikz} \usepackage{filecontents} \definecolor{tb_color_1}{RGB}{245,124,0} \definecolor{tb_color_2}{RGB}{0,167,247} \pgfplotscreateplotcyclelist{tb}{ semithick,tb_color_1\\% semithick,tb_color_2\\% } \begin{document} \centering \begin{tikzpicture} \begin{axis}[ cycle list name=tb, grid=both, grid style={solid,gray!30!white}, axis lines=middle, xlabel={step}, ylabel={adversarial loss of the generator (unitless)}, x label style={at={(axis description cs:0.5,-0.1)},anchor=north}, y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south}, ] \addplot table [x=Step, y=Value, col sep=comma] {run-.-tag-advg.csv}; \end{axis} \end{tikzpicture} \end{document}

  • plot the implicit function using Lua
    by 青山漫步 on April 14, 2025 at 8:23 am

    I want to use the built-in Lua language in LuaLaTeX to plot the implicit function x*y^2+2*x^3*y^3-y-1=0. My idea is to plot the points within the rectangular region [−5,5]×[−5,5] that satisfy the above equation. Here is my code, but I didn't get any output. Can you tell me where I went wrong? % !TEX program = Lualatex % !Mode:: "TeX:UTF-8" \DocumentMetadata{} \documentclass[12pt]{article} \usepackage{luacode} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{luacode} function mefun (x,y) return x*y^2+2*x^3*y^3-y-1 end function Imfun(n) --[-5,5]*[-5,5] for i=0, n do ti=-5.0+10.0*i/n for j=0, n do tj=-5.0+10.0*j/n temp=mefun(ti,tj) if (math.abs(temp))<1e-3 then tex.print(string.format('(%2.5f, %2.5f)', ti, tj)," \\par") else break end end end end \end{luacode} \begin{document} \begin{tikzpicture} \begin{axis}[xlabel=$x$, ylabel=$y$] %\addplot coordinates{ \addplot[cyan,smooth,line width=1.0pt] coordinates{ \luadirect{ Imfun(100) } }; \end{axis} \end{tikzpicture} \end{document}

  • Gap between pgfplots `plot`s
    by Mr.Hedge on April 13, 2025 at 2:18 pm

    I have the following code to draw a continuous function that is given by three different formulas: \documentclass[tikz, margin=3mm]{standalone} \usepackage{tikz} \usetikzlibrary{shapes, backgrounds, arrows.meta, fit} \usepackage[dvipsnames]{xcolor} \usepackage{pgfplots} \usepgfplotslibrary{fillbetween} \pgfplotsset{compat=1.18} \input{Utils/Makra/Axis} \begin{document} \begin{tikzpicture}[ background grid/.style={thin, dotted, draw=gray,step=.5cm}, >=Stealth, remember picture, ] \newcommand{\filledPoints}{(4, 1)} \newcommand{\emptyPoints}{(-4, 3)} \Axis[ xmin=-4.5, xmax=4.99, ymin=-3.5, ymax=4.99, ]{% \path[name path=xaxis] (axis cs:-4, 0) -- (axis cs:4, 0); % Wykres funkcji \addplot [name path = A,domain=-4:-2, samples=2, thick, color=Red] {3}; \addplot [name path = B,domain=-2:2, samples=2, thick, color=Red] {-x+1}; \addplot [name path = C,domain=2:4, samples=2, thick, color=Red] {x-3}; \addplot [only marks, mark=*, mark size=1pt, color=red, on layer=axis foreground, % Rysuj na warstwie nad osiami ] coordinates {\filledPoints}; \addplot [only marks, mark=*, mark size=1pt, color=red, fill=white, on layer=axis foreground, % Rysuj na warstwie nad osiami ] coordinates {\emptyPoints}; \node[Red] at (axis cs:2,1) {$f(x)$}; %Domain \begin{pgfonlayer}{axis foreground} \draw[Green, thick] (axis cs:-4,0) -- (axis cs:4, 0); \addplot [only marks, mark=*, mark size=1pt, color=Green] coordinates {(4,0)}; \addplot [only marks, mark=*, mark size=1pt, color=Green, fill=white] coordinates {(-4,0)}; \addplot [Red, opacity=0.25] fill between [of = A and xaxis,soft clip={domain=-4:-2}]; \addplot [Red, opacity=0.25] fill between [of = B and xaxis,soft clip={domain=-2:2}]; \addplot [Red, opacity=0.25] fill between [of = C and xaxis,soft clip={domain=2:4}]; \end{pgfonlayer} \begin{pgfonlayer}{axis foreground} \node[rectangle, fill=Green!20, draw, rounded corners,on layer=axis foreground] at (axis cs:0, -3) {\textbf{$D_f=(-4,4]$}}; \end{pgfonlayer} } \end{tikzpicture} \end{document} The problem is that the edges of each plot are not connected and the below gap is present: How to fix it?

  • Loops inside a pgfplots axis [duplicate]
    by Michael Dorner on April 11, 2025 at 11:03 am

    I'm encountering unexpected behavior when looping over a list of strings using \foreach inside a pgfplots axis environment. Here’s a minimal example: \begin{tikzpicture} \begin{axis} \foreach \testname/\yA/\yB in { Test 1/76.36/81.82, Test 2/60.00/43.64 }{ \addplot[mark=*, thick] coordinates {(0,\yA) (1,\yB)} node [pos=0.5, above, sloped] {testname}; } \end{axis} \end{tikzpicture} This produces the expected plot, with lines connecting the coordinates: However, when I try to replace the hardcoded label testname with the variable \testname: node [pos=0.5, above, sloped] {\testname} I get the following error: Undefined control sequence. \pgfplotsretval ....5, above, sloped] {\testname} I learned from here (thank you very much!) that loops inside axis can be tricky, but I don't know to solve the problem with the suggested \pgpflotsinvokeforeach.

  • pgfplots addplot scatter with independently varying size and color
    by John on April 8, 2025 at 8:24 pm

    I am trying to make a scatter plot where the color varies according to one column from a table, while the size of the marks varies according to another column from the same table. I found this answer which allows to get color and mark size from the same column, is there a way to modify it so that the size is given by another column (e.g. D) in the table? \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \begin{document} \pgfplotstableread{ A B C 0 5 -1 0.5 2 0 1 7 1 1.5 11 1.5 }\mytable \begin{tikzpicture} \begin{axis}[ colorbar ] \addplot[ scatter, only marks, scatter src=explicit, mark=*, scatter/use mapped color={ draw=mapped color, fill=mapped color, }, scatter/@pre marker code/.append style= {/tikz/mark size={.6pt+\pgfplotspointmetatransformed/650}}] table[meta expr=abs(\thisrow{C})] {\mytable}; \end{axis} \end{tikzpicture} \end{document}

  • Coloring a world map and some coordinates
    by Angelo Aliano Filho on April 8, 2025 at 2:31 am

    I have followed the wonderfull project in click here where I can to colour cowtries with prefered colors. Works perfecty for me. The code is presented below: \documentclass[varwidth=2\linewidth]{standalone} \usepackage{tikz} \input{mundo} \begin{document} \begin{tikzpicture} \tikzset{set state val/.style args={#1/#2}{#1={fill=red!#2!blue}}} \tikzset{set state val/.list={ Greenland/0, Colombia/16, Canada/33, Russia/50, Brazil/66, Mexico/83.3, India/99, Paraguay/50 } } \WORLD[every state={draw=white, thick, fill=black!30}] \fill (India) circle (2pt); \fill (Brazil) circle (2pt); \draw (Brazil) -- (India); \end{tikzpicture} \end{document} The result is wonderfull: where mundo.tex is here: enter link description here My question is: If I provide some coordinates (eg Paris = Lat,Long = 46.5687, 3.5653, London = Lat,Long= 51.6313, 0.08172), How can I used this code to draw circles of 2pt above these cities? In the code above, I have tried to connect Brazil to India, but the result is bad. I would like to provide the geographical coordinates, label, and next conect them. Thank you so much!

  • Combine the legend for the same line types
    by Антон on April 4, 2025 at 8:40 am

    I need to avoid repetitions in the legend captions, so I want to draw two lines (red and blue) in the legend and add one signature to them $x^2$, then draw two more lines in the legend (red and blue) and one signature ($\sin(x)$). \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel={$x$}, ylabel={$y$}, legend pos=outer north east, legend style={draw=none} ] \addplot[color=red, domain=0:5, samples=100, mark size=1.4pt, mark repeat=10, mark=square*, mark options={solid}] {x^2}; \addlegendentry{$x^2$} \addplot[color=red, domain=0:5, samples=100, mark size=2.5pt, mark repeat=10, mark=diamond, mark options={solid}] {sin(deg(x))}; \addlegendentry{$\sin x$} \addplot[color=blue, domain=0:5, samples=100, mark size=1.4pt, mark repeat=10, mark=square*, mark options={solid}] {x^2+1}; \addlegendentry{$x^2$} \addplot[color=blue, domain=0:5, samples=100, mark size=2.5pt, mark repeat=10, mark=diamond, mark options={solid}] {sin(deg(x))+1}; \addlegendentry{$\sin x$} \end{axis} \end{tikzpicture} \end{document} Another possible solution is to make the colors of the lines in the legend black and display one line for each type of lin: \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel={$x$}, ylabel={$y$}, legend pos=outer north east, legend style={draw=none}, every legend image post/.style={black} ] \addplot[color=red, domain=0:5, samples=100, mark size=1.4pt, mark repeat=10, mark=square*, mark options={solid}] {x^2}; \addlegendentry{$x^2$} \addplot[color=blue, domain=0:5, samples=100, mark size=1.4pt, mark repeat=10, mark=square*, mark options={solid}, forget plot] {x^2+1}; \addplot[color=red, domain=0:5, samples=100, mark size=2.5pt, mark repeat=10, mark=diamond, mark options={solid}] {sin(deg(x))}; \addlegendentry{$\sin x$} \addplot[color=blue, domain=0:5, samples=100, mark size=2.5pt, mark repeat=10, mark=diamond, mark options={solid}] {sin(deg(x))+1}; \end{axis} \end{tikzpicture} \end{document} You can display one signature and hide the second one, while adding a vertical indentation to the second one: \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel={$x$}, ylabel={$y$}, legend pos=outer north east, legend style={draw=none} ] \addplot[color=red, domain=0:5, samples=100, mark size=1.4pt, mark repeat=10, mark=square*, mark options={solid}] {x^2}; \addlegendentry{$x^2$} \addplot[color=blue, domain=0:5, samples=100, mark size=1.4pt, mark repeat=10, mark=square*, mark options={solid}] {x^2+1}; \addlegendentry[yshift=-0.2cm]{} \addplot[color=red, domain=0:5, samples=100, mark size=2.5pt, mark repeat=10, mark=diamond, mark options={solid}] {sin(deg(x))}; \addlegendentry{$\sin x$} \addplot[color=blue, domain=0:5, samples=100, mark size=2.5pt, mark repeat=10, mark=diamond, mark options={solid}] {sin(deg(x))+1}; \addlegendentry[yshift=-0.2cm]{} \end{axis} \end{tikzpicture} \end{document}

  • Using mixed formatted ticks
    by Patricio on April 3, 2025 at 12:48 pm

    I'm trying to label my figure so that the exact value is shown (rather the approximation I'm using to actually plotting it). In the code below I tried to put those values directly into the tick lists but, unsurprisingly, I I get the !Undefined control sequence error. I'm guessing the xticks is expected to be followed by a list of numbers, not of formatted labels. \documentclass{book} \usepackage{tikz,pgfplots} \begin{document} \begin{figure} \centering \footnotesize \begin{tikzpicture} \begin{axis}[ xtick={2/3,\sqrt{2}}, ytick={1/3,\sqrt{2}}, axis x line=bottom, axis y line=left, xmin=0,xmax=2, ymin=0,ymax=2] \addplot+[black,nodes near coords,only marks,point meta=explicit symbolic] table[meta=label]{ x y label 0.6667 0.3333 $y$ 1.4142 1.4142 $x$ }; \end{axis} \end{tikzpicture} \end{figure} \end{document} I'd like the ticks to read $\frac{2}{3}$, $\sqrt{2}$ and so on.

  • Why does \addplot3 cause the other lines to be covered by the ticks [duplicate]
    by BlackCoffee on April 2, 2025 at 7:07 pm

    \documentclass[tikz, border=0pt]{standalone} \usepackage{pgfplots} \usepgfplotslibrary{patchplots} \pgfplotsset{compat=1.16} \begin{document} \begin{tikzpicture}[scale = 1.05] \begin{axis}[ view={0}{90}, scatter, only marks, colorbar, colormap/bluered, mark options={scale=1.0}, grid=both, grid style={black!10}, legend style={at={(0.4,0.95)}}, legend cell align={left}, x post scale=1, mark size=3pt, xmode=log, ymode=log, height=12cm, width=12cm, xmin=10, xmax=1500000, ymin=10, ymax=1500000, xtick={10, 100, 1000, 10000, 100000}, ytick={10, 100, 1000, 10000, 100000}, ] \addplot3[ultra thick, fill opacity=0.5, draw opacity=0, forget plot] coordinates {(1000000.0, 6698.98, 3691.47) (966.55, 785.25, 14427.23)}; \addplot[domain=1:200000, samples=2, thick, black, smooth, mark size=0, opacity=.7] {x}; \addplot[domain=1:100000, samples=2, thick, black!70!green, smooth, mark size=0, opacity=.7] {2*x}; \addplot[domain=1:20000, samples=2, thick, black!50!green, smooth, mark size=0, opacity=.7] {10*x}; \addplot[domain=1:200000, samples=2, thick, black!50!green, smooth, mark size=0, forget plot, opacity=.7] {1/10*x}; \addplot[domain=1:200000, samples=2, thick, black!70!green, smooth, mark size=0, forget plot, opacity=.7] {1/2*x}; \addplot[domain=1:200000, samples=2, thick, black!30!green,, smooth, opacity=.7, mark size=0, opacity=.7 ] {1/100*x}; \addplot[domain=1:200000, samples=2, thick, black!0!green,, smooth, mark size=0, opacity=.7] {1/1000*x}; \addplot[thick, samples=2, smooth , brown, mark size=0] coordinates {(200000,1.0)(200000,200000)}; \addplot[thick, samples=2, smooth , brown, mark size=0, forget plot] coordinates {(1.0, 200000)(10000000.0, 200000)}; \addplot[thick, samples=2, smooth, red, mark size=0] coordinates {(447200.0, 1.0) (447200.0, 200000)}; \addplot[thick, samples=2, smooth, orange, mark size=0] coordinates {(1000000.0, 1.0)(1000000.0, 200000)}; \end{axis} \end{tikzpicture} \end{document} In the code above, the tick lines cover the diagonal lines. I don't want this behavior. I also noticed that when I remove the \addplot3, the lines render correctly. Could I have some help?

  • Polar Graph Fill Between
    by Nick B on April 2, 2025 at 11:39 am

    I was able to shade the correct area between my two curves, however, the axis is erased. Is there a better way to do this? I am struggling with intersection use and have tried soft clip between their points of intersection (5pi/6 and pi/6), but that does not work. Any help is appreciated. \documentclass[border=5mm]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{fillbetween} \usetikzlibrary{backgrounds,arrows.meta} \pgfplotsset{ interpret as polar/.style={ x filter/.code=\pgfmathparse{cos(rawx)*rawy}, y filter/.code=\pgfmathparse{sin(rawx)*rawy} } } \begin{document} \begin{tikzpicture}[>=Triangle] \begin{axis}[ xtick distance=2, ytick distance=2, axis lines=center, axis equal image, enlargelimits=true, ] \addplot[name path=A, very thick, domain=0:360, samples=100, smooth, interpret as polar ] (x,{1+sin(x)}); \addplot[name path=B, very thick, domain=0:360, samples=100, smooth, interpret as polar ] (x,{3*sin(x)}); \path[name path=xaxis] (axis cs: -1,0) -- (axis cs:1,0); \addplot[blue,opacity=0.5] fill between[of=B and A]; \node[anchor=center,label=north west:\(R\)] at (0,0){}; \addplot[white] fill between[of=A and xaxis]; \end{axis} \end{tikzpicture} \end{document} \end{document}

  • Working with arrays in tikz
    by Mr.Hedge on March 30, 2025 at 2:49 pm

    Is it possible to add an items to the array in foreach loop, and then loop over all array items? Pseudo code: \def\myarray{} foreach \n in {0,1,2,3,4} { \def\myarray{\myarray+\n} } \foreach \el in \myarray { \node[] at (\el,0) {\el}; What packages do you recommend for this kind of things? I want to store them numbers and strings as well.

  • is there a way to set all of the tikz code in a file to exactly the same dimensions without scaling?
    by Nate3384 on March 30, 2025 at 8:08 am

    I'm working in the ERT environment in the latest version of LyX, for example I have two graphs one where it's limits are from (-1.5,-0.2)(6.5,6) and another where the limits are (-1.5,-0.1)(1.5,0.2) and when I try to do scaling it just does "dumb" scaling. for example: \documentclass{article} \usepackage{colortbl} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} % Draw axes \draw[->] (-1.5,0) -- (6.5,0) node[right] {$x(t)$}; \draw[->] (0,-0.2) -- (0,6) node[above] {$y(t)$}; % Grid \draw[dashed, gray] (-1.5,0) grid[xstep=1,ystep=1] (6.5,6); % Plot function \draw[blue, thick, domain=0:6.5, samples=40] plot (\x, {5 - 5*exp(-2*\x)}); % Step function effect (zero for x < 0) \draw[blue, thick] (-1,0) -- (0,0); % Labels at key points \node[below left] at (0,0) {0}; \node[left] at (0,5) {5}; \node[below] at (5,0) {5}; \node[below] at (-1,0) {-1}; \node[anchor=south] at (4, 5) {$y = (5 - 5e^{-5x}) u(t)$}; \end{tikzpicture} \begin{tikzpicture} % Draw axes \draw[->] (-1.5,0) -- (1.5,0) node[right] {$x(t)$}; \draw[->] (0,-0.1) -- (0,0.3) node[above] {$y(t)$}; % Grid \draw[dashed, gray] (-1.5,0) grid[xstep=1,ystep=0.1] (1.5,0.3); % Plot function \draw[blue, thick, domain=0:2.5, samples=100] plot (\x, {0.1 - 0.1*exp(-5*\x)*(cos(deg(5*\x)) + sin(deg(5*\x)))}); % Step function effect (zero for x < 0) \draw[blue, thick] (-1,0) -- (0,0); % Labels at key points \node[below left] at (0,0) {0}; \node[left] at (0,0.1) {0.1}; \node[below] at (-1,0) {-1}; \end{tikzpicture} \end{document} gives me the following two graphs: I think you can clearly see the problem, so I think the more general question would be how to still have exact graphs (the curves need to pass through specific points) while having them parameterized with the page height? for example, I want all of them to be around 15-20% of page height. i know a dumb solution would be to graph the normalized graph and just give specific values to the nodes, but this seems like a bad way of doing things, open to suggestion and I must add I'm not very technical so go easy on me haha

  • How to calculate and remember values within \foreach loop in tikz
    by Mr.Hedge on March 30, 2025 at 2:45 am

    I already was asking about it here How to set value in foreach loop in tikz but the problem is now more involved. I have a command to draw an interval and the very first thing to do is to calculate the numbers within that interval and to do that I want to calculate maximum and minimum values from the set of values. The input for my command is a list like this: \numbOne/\boolOne/\numbTwo/\boolTwo where numbOne and numbTwo are either a numbers (positive or negative) or a string infinity to denote that the interval is the infinite one.So the first step is to calculate the maximum and minumum values this way: loop over all intervals and if a number is ifninity, then take the second end of the interval and add or subtract \infinityOffset calculate the maximum and minimum at each step This is my attempt \pgfmathsetmacro{\xmax}{0} \pgfmathsetmacro{\xmin}{0} \pgfmathsetmacro{\padding}{1} % Padding around intervals \pgfmathsetmacro{\infinityOffset}{3} % Padding around intervals \foreach[remember=\xmax] \numbOne/\boolOne/\numbTwo/\boolTwo in {#1} { \ifx\numbOne\myinfinitystr\pgfmathsetmacro{\numbOne}{\numbTwo-\infinityOffset}\fi \ifx\numbTwo\myinfinitystr\pgfmathsetmacro{\numbTwo}{\numbOne+\infinityOffset}\fi \pgfmathsetmacro{\xmin}{min(\xmin,\numbOne)} \pgfmathsetmacro{\xmax}{max(\xmax,\numbTwo)} \draw[fill=red!20] (\numbOne,0) rectangle (\numbTwo,1); } There are two problems - one is that the loop does not update the \xmax value even though I used remember and the seconds problem is that I would like to update \xmin as well within a single loop rather than creating another one. Does remember support two variables? Here is full code: \documentclass{article} \usepackage{tikz} \def\myinfinitystr{infinity} \NewDocumentCommand{\drawInterval}{m}{% \begin{tikzpicture}[scale=0.5] \pgfmathsetmacro{\xmax}{0} \pgfmathsetmacro{\xmin}{0} \pgfmathsetmacro{\padding}{1} % Padding around intervals \pgfmathsetmacro{\infinityOffset}{3} % Padding around intervals \foreach[remember=\xmax] \numbOne/\boolOne/\numbTwo/\boolTwo in {#1} { \ifx\numbOne\myinfinitystr\pgfmathsetmacro{\numbOne}{\numbTwo-\infinityOffset}\fi \ifx\numbTwo\myinfinitystr\pgfmathsetmacro{\numbTwo}{\numbOne+\infinityOffset}\fi \pgfmathsetmacro{\xmin}{min(\xmin,\numbOne)} \pgfmathsetmacro{\xmax}{max(\xmax,\numbTwo)} \draw[fill=red!20] (\numbOne,0) rectangle (\numbTwo,1); } \pgfmathsetmacro{\xmin}{\xmin-\padding} % Add padding to the minimum \pgfmathsetmacro{\xmax}{\xmax+\padding} % Add padding to the maximum \node[] at (0,-3) {\xmax}; \draw[help lines,dashed] (\xmin,0) grid (\xmax,2); \draw (\xmin,0) -- (\xmax,0); %draw the horizontal axis % \foreach \x in {\xmin,...,\xmax} { % \draw (\x,0.2) -- (\x,-0.2) node[below] {\x}; % draw the ticks % } \end{tikzpicture}% } \begin{document} \drawInterval{-22/true/0/false,13/false/infinity/true} \end{document}

  • Fill area between hyperbola and line with pgfplots
    by Magnivul on March 29, 2025 at 7:25 pm

    This is my first time using TikZ and pgfplots, and I've been trying, to no avail, to color the area enclosed by the graphs of the functions x^2 - y^2 = 9 and y = 4x - 16. My problem is that fillbetween either fills area that isn't enclosed, or doesn't fill area that is enclosed, depending on the domain I try to clip it to. Currently what I've got looks like this: And I want the area at the bottom that is not enclosed by the graphs not to be colored. Any help would be much appreciated. Here is the TeX code: \documentclass{standalone} \usepackage[svgnames]{xcolor} \usepackage{tikz,pgfplots,tkz-euclide,tkz-graph} \pgfplotsset{compat=1.18} \usetikzlibrary{calc,shapes,angles,patterns,shadows,arrows.meta} \usepgfplotslibrary{statistics,fillbetween} \pgfplotsset{ standard/.style={ axis line style = thick, trig format=rad, axis x line=middle, axis y line=middle, xlabel = {\( x \)}, ylabel = {\( y \)}, every axis x label/.style={at={(current axis.right of origin)},anchor=west}, every axis y label/.style={at={(current axis.above origin)},anchor=south} } } \begin{document} \begin{tikzpicture} \begin{axis}[standard, scale only axis, ticklabel style = {font = \tiny}, grid = both, grid style = {dashed, gray!50}, xmin = -1, xmax = 7, ymin = -3, ymax = 5, xtick = {0,...,6}, ytick = {-2,-1,..., 4}, domain = 3:7, samples = 1000] \addplot[name path = f, line width = 0.5mm, Teal]{4*x - 16}; \addplot[name path = g1, line width = 0.5mm, MediumPurple]{sqrt(x^2 - 9)}; \addplot[name path = g2, line width = 0.5mm, MediumPurple]{-sqrt(x^2 - 9)}; \node[Teal] at (5.8, 1.5) {\( y = 4x - 16 \)}; \node[MediumPurple] at (2.2, 2.5) {\( x^2 - y^2 = 9 \)}; \addplot[SteelBlue!50, opacity = 0.8] fill between [of = f and g1, soft clip = {domain = 3:5}]; \end{axis} \end{tikzpicture} \end{document}

  • How to edit numbering on colorbar
    by BlackCoffee on March 28, 2025 at 11:09 pm

    Currently, my colorbar looks like but it would be much better if it had 14k, instead of the $\cdot 10^4$ at the top. Is there a way to do this? My current axis code is \documentclass[tikz, border=0pt]{standalone} \usepackage{pgfplots} \usepgfplotslibrary{patchplots} \pgfplotsset{compat=1.16} \begin{document} \begin{tikzpicture}[scale = 1.05] \begin{axis}[ view={0}{90}, scatter, only marks, colorbar, colormap/bluered, mark options={scale=1.0}, grid=both, grid style={black!10}, legend style={at={(0.4,0.95)}}, legend cell align={left}, x post scale=1, mark size=3pt, xmode=log, ymode=log, height=12cm, width=12cm, xmin=10, xmax=1500000, ymin=10, ymax=1500000, xtick={10, 100, 1000, 10000, 100000}, ytick={10, 100, 1000, 10000, 100000}, ] \addplot3[ultra thick, fill opacity=0.5, draw opacity=0, forget plot] coordinates {(1000000.0, 6698.98, 3691.47) (966.55, 785.25, 14427.23)}; \end{axis} \end{tikzpicture} \end{document}

  • Foreach/pgfinvokeforeach in pgfplot groupplot
    by Paul on March 26, 2025 at 5:50 pm

    Is there a way to have multiple variables with the command pgfinvokeforeach like with the foreach command ? I want to draw multiple subplots with groupplots. All my data are saved in a csv file and my columns/variables names are like "PcondT1matlab, PcondT2matlab, PcondD1matlab ...". I also want to change the ymax depending on the variable being plotted. It seemed that foreach doesn't work well with groupplot. And also because of the way I nammed my variables, pgfplot can't evaluate properly the variable name with Pcond\xmatlab (I also tried Pcond\n{}matlab it does not work). pgfplotsinvokeforeach seems to work with one iteration variable. But when I tried to add a second iteration variable to change the ylimit at every iteration, I got this error : "! Illegal parameter number in definition of \pgfmathfloat@expression." My minimal working example is : \documentclass[]{article} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \begin{filecontents*}{MWE.csv} itsimu, PcondT1matlab, PswT1matlab, PcondT1plecs, PswT1plecs,... 1, 150,580,145,590 2, 450, 1200, 475, 1350 \end{filecontents*} \pgfplotsset{width=8cm,height = 5cm,compat=1.9,scale only axis=false} \begin{document}\begin{tikzpicture} \pgfplotsset{set layers} %%%%%%%%%%%%%%%%%%%%%%% %% First series : matlab results (Pcond and Psw) in W \begin{groupplot}[group style={group size=2 by 5}, ybar stacked, table/col sep=comma] \pgfplotsinvokeforeach{T1,D1,T2}{% \nextgroupplot[ymin=0, bar shift={-2*\pgfplotbarwidth}, %ymax=#2, title = {#1} ] \addplot[fill={color2}] table [trim cells=true,y expr=\thisrow{Pcond#1matlab}/1000, x=itsimu] {MWE.csv}; \addplot[fill={color4}] table [trim cells=true,y expr=\thisrow{Psw#1matlab}/1000, x=itsimu] {MWE.csv}; }\end{groupplot} %%%%%%%%%%%%%%%%%%%%%%% %% Second series : Plecs results (Pcond and Psw) in W \begin{groupplot}[group style={group size=2 by 5}, ybar stacked, table/col sep=comma] \pgfplotsinvokeforeach{T1,D1,T2}{ \nextgroupplot[ ymin=0, bar shift={-0.5*\pgfplotbarwidth}, %ymax=4, title = {#1} ] \addplot[fill={color1}] table [trim cells=true,y expr=\thisrow{Pcond#1plecs}/1000, x=itsimu] {MWE.csv}; \addplot[fill={color3}] table [trim cells=true,y expr=\thisrow{Psw#1plecs}/1000, x=itsimu] {MWE.csv}; }\end{groupplot} \end{tikzpicture}\end{document} Do you know a way arround to be able to have two or more iteration variables with the column name of the data to be plotted and the ylim for instance ? thanks EDIT As requested by @Rmano, I updated my MWE. As you can see this code works without error but the y range is not the same for the two groupplots. I want to use the \pgfplotsinvokeforeach with two parameters : one for the name of data to be plotted (T1,T2,D1,...) and one to set the ymax for each data (like (4500,10,2500,...) (like ymax = #2). My csv file is like : itsimu Iload PcondT1plecs PswT1plecs TjT1plecs PcondT1matlab PswT1matlab TjT1matlab PcondT2plecs PswT2plecs TjT2plecs PcondT2matlab PswT2matlab TjT2matlab 1 150 119 574 115 125 600 120 184 35 58 190 37 60 2 800 150 850 140 155 912 145 250 80 95 260 89 100

  • Color not showing up properly in legend of Tikz picture graph
    by aimalik on March 26, 2025 at 8:16 am

    I am trying to plot a map of indifference curve for complements. Addlegendentry is not showing the proper colors in the legend key. How do I fix this? \begin{center} \begin{tikzpicture} \begin{axis}[ axis lines = left, xlabel = \(L\), ylabel = {\(R\)}, xmin=0, ymin=0, ymax=10, ] %Below the red graph is defined \addplot [ range=0:10, domain=4:10, samples=100, color=red, ] {4}; \addlegendentry{\(min\{L,R\}=4\)} \addplot[thick, samples=50, smooth,domain=4:10,red] coordinates {(4,4)(4,10)}; %Below the blue graph is defined \addplot [ range=0:10, domain=2:10, samples=100, color=blue, ] {2}; \addlegendentry{\(min\{L,R\}=2\)} \addplot[thick, samples=50, smooth,domain=2:10,blue] coordinates {(2,2)(2,10)}; %Below the green graph is defined \addplot [ range=0:10, domain=6:10, samples=100, color=green, ] {6}; \addlegendentry{\(min\{L,R\}=6\)} \addplot[thick, samples=50, smooth,domain=6:10,green] coordinates {(6,6)(6,10)}; %Below the black line is defined \addplot [ range=0:10, domain=0:10, samples=100, color=black, ] {x}; \addlegendentry{\(R=L\)} \end{axis} \end{tikzpicture} \end{center} This generates the graph below where the legend colors are clearly wrong. Would be grateful for any help!

  • How to create animation in TikZ pgfplot
    by Mr.Hedge on March 25, 2025 at 1:57 am

    How to create an animation like this in tikz? I would like to do this for this sample function: \documentclass[tikz, margin=3mm]{standalone} \usepackage{tikz} \usetikzlibrary{shapes, backgrounds, arrows.meta, fit, calc,tikzmark} \usepackage[dvipsnames]{xcolor} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture}[ % show background grid, background grid/.style={thin, dotted, draw=gray,step=.5cm}, >=Stealth, remember picture, ] \begin{axis}[ xmin=-3.5, xmax=3.99, ymin=-3.5, ymax=3.99, xtick distance=1, ytick distance=1, xticklabels=\empty, yticklabels=\empty, % extra y ticks={1}, % Dodatkowy tick na osi Y (dla b=1) % extra y tick labels={$b$}, % Oznaczenie wartości b % extra x ticks={-1}, % Dodatkowy tick na osi Y (dla b=1) % extra x tick labels={$-\frac{b}{a}$}, % Oznaczenie wartości b axis lines=middle, % Osie przechodzą przez środek axis line style={-Stealth}, % Strzałki na osiach axis on top, % Osie na wierzchu xlabel={$X$}, % Oznaczenie osi X ylabel={$Y$}, % Oznaczenie osi Y xlabel style={at={(ticklabel* cs:1)}, anchor=north east}, % Pozycja etykiety X ylabel style={at={(ticklabel* cs:1)}, anchor=north west}, % Pozycja etykiety Y grid=both, % Dodaj siatkę grid style={dotted, gray!50}, % Styl siatki: kropkowana, szara set layers, clip mode=individual ] \begin{pgfonlayer}{axis foreground} % Wykres funkcji \addplot [domain=-2:2, samples=100, thick, color=Red] {x + 1}; \end{pgfonlayer} \end{axis} \end{tikzpicture} \end{document}

  • Minimal working example for violinplot by tikz
    by Fellow InstituteOfMathophile on February 25, 2025 at 3:46 am

    I am trying to create a violin plot using tikz it does not work. The following code is adapted from tikzviolinploots \documentclass{article} \usepackage{pgfplots} \usepackage{tikzviolinplots} \begin{document} \begin{tikzpicture} \violinsetoptions[ data points, scaled, ]{ xmin=0,xmax=6, ymin=-4,ymax=6, title={Plotting Some Data}, xlabel={Groups}, ylabel={Some property}, xlabel style={ yshift = {-2*height("a")} }, ymajorgrids=true, } \violinplotwholefile[% primary color=orange, secondary color=black, batch indexes={C,B,A,D,E}, batch spacing=1.0, batch labels={% $\alpha$, $\beta$, $\gamma$, $\delta$, $\epsilon$ }, col sep=tab, dataset size=2pt, dataset mark=diamond*, dataset fill=blue!50!white, dataset fill opacity=1.0, ]{ A B C D E 0.3 -2.1 3.50 2.89 1.00 0.41 -1.9 3.55 2.88 1.06 0.45 -1.5 3.55 3.13 1.00 0.46 -1.3 3.60 2.69 1.20 0.46 -1.3 3.60 2.78 1.00 0.46 -1.27 3.60 2.83 1.35 0.47 -1.26 3.65 3.08 1.00 0.47 -1.26 3.65 3.08 1.53 0.48 -1.24 3.65 2.73 1.00 0.51 -1.2 3.65 3.08 1.73 0.57 -1.13 3.65 3.24 1.00 } \end{tikzpicture} \end{document} The following error is produced by TexShop Package pgfplots Warning: running in backwards compatibility mode (unsuitable t ick labels; missing features). Consider writing \pgfplotsset{compat=1.18} into your preamble. on input line 4. ./violinplot.tex:37: Package pgfplots Error: \pgfplotslistfront\ from \thevioli n@dataset@table\ although list is EMPTY. See the pgfplots package documentation for explanation. Type H <return> for immediate help. ... l.37 ]{violinandboxplotexample.txt} ? The error produced by Overleaf is Package pgfkeys Error: I do not know the key '/violinplotwholefile/batch indexes', to which you passed 'C,B,A,D,E', and I am going to ignore it. Perhaps you misspelled it. Package pgfkeys Error: I do not know the key '/violinplotwholefile/batch spacing', to which you passed '1.0', and I am going to ignore it. Perhaps you misspelled it. Package pgfkeys Error: I do not know the key '/violinplotwholefile/batch labels', to which you passed '$\alpha $, $\beta $, $\gamma $, $\delta $, $\epsilon $', and I am going to ignore it. Perhaps you misspelled it. Package pgfplots Error: Could not read table file ' A B C D E 0.3 -2.1 3.50 2.89 1.00 0.41 -1.9 3.55 2.88 1.06 0.45 -1.5 3.55 3.13 1.00 0.46 -1.3 3.60 2.69 1.20 0.46 -1.3 3.60 2.78 1.00 0.46 -1.27 3.60 2.83 1.35 0.47 -1.26 3.65 3.08 1.00 0.47 -1.26 3.65 3.08 1.53 0.48 -1.24 3.65 2.73 1.00 0.51 -1.2 3.65 3.08 1.73 0.57 -1.13 3.65 3.24 1.00 ' in 'search path=.'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try `row sep=crcr' and terminate your lines with `\\' (refer to the pgfplotstable manual for details). Btw I also tried the suggestion to put an external .dat file or adding \\ or row step = crcr. None of them works. I also notice there is another post. But the code there contains a minted package which causes some problem. I believe it is related to -shell-escape. I want a minimal working example without using that particular command and possibly without using external .dat file.

  • Graphing the intersection of 2 planes on Overleaf
    by Katya on October 19, 2024 at 11:40 am

    I am trying to graph the intersection of the planes 4x-y+3z=4 and 2x-3y+4z=-3 on Overleaf with pgfplots, but I want to include axes and I want both planes to be light grey. I tried copying the code from this old post but there were no axes and the shading didn't work (both planes showed up as bright pink). Also, the line \usetkzobj{all} in the preamble kept showing errors. I don't have code yet because I'm not sure where to start. Edit: I think I want it to look like something like the first picture but without the textures on the planes and that extra blue line intersecting? Maybe axes are too much of an ask. I just wanted to visually represent that two planes always intersect in a line.

  • Missing labels in barchart
    by Yevin Christopher on March 18, 2024 at 9:31 pm

    I'm trying to draw a barchart but the text that I underlined and colored as green doesn't seem to display. This is how it appears. The following is the code. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.8} \newcommand{\ImageWidth}{11cm} \usepackage{tikz} \usetikzlibrary{decorations.pathreplacing,positioning, arrows.meta} \usetikzlibrary{patterns} \begin{document} \begin{figure}[ht] \centering \scalebox{0.72}{ % Adjust the scale factor as needed \begin{tikzpicture} \begin{axis}[ height=19.58cm, width=15.44cm, xbar, xmin=-1000, xmax=25000, xlabel={Time elapsed since the first kernel driver (module) was unloaded (in seconds)}, symbolic y coords={ \underline{\textcolor{red}{mdd.sys}}, \underline{\textcolor{red}{Beep.SYS$^4$}}, \underline{\textcolor{red}{Beep.SYS$^3$}}, \underline{\textcolor{red}{Beep.SYS$^2$}}, \underline{\textcolor{red}{Beep.SYS$^1$}}, \underline{\textcolor{red}{imapi.sys}}, \underline{\textcolor{red}{processr.sys}}, \underline{\textcolor{red}{Cdaudio.SYS}}, \underline{\textcolor{red}{Sfloppy.SYS}}, \underline{\textcolor{green}{kmixer.sys}}, \underline{\textcolor{green}{drmkaud.sys}}, \underline{\textcolor{green}{DMusic.sys}}, \underline{\textcolor{green}{aec.sys}}, \underline{\textcolor{green}{swmidi.sys}}, \underline{\textcolor{green}{splitter.sys}}, \underline{\textcolor{green}{Serial.SYS}}, \underline{\textcolor{green}{Parport.SYS}}, \underline{\textcolor{green}{imapi.sys}}, \underline{\textcolor{green}{redbook.sys}}, \underline{\textcolor{green}{intelppm.sys}}, \underline{\textcolor{green}{Cdaudio.SYS}}, \underline{\textcolor{green}{Sfloppy.SYS}}, \underline{\textcolor{green}{Flpydisk.SYS}}, \underline{\textcolor{green}{Fdc.SYS}} }, ytick=data, nodes near coords, nodes near coords align={horizontal}, scaled x ticks=false, ] \addplot [fill=red!30,draw=red, postaction={pattern=north east lines}] coordinates { (13450,\underline{\textcolor{red}{mdd.sys}}) (8168,\underline{\textcolor{red}{Beep.SYS$^4$}}) (8168,\underline{\textcolor{red}{Beep.SYS$^3$}}) (8168,\underline{\textcolor{red}{Beep.SYS$^2$}}) (8167,\underline{\textcolor{red}{Beep.SYS$^1$}}) (0,\underline{\textcolor{red}{imapi.sys}}) (0,\underline{\textcolor{red}{processr.sys}}) (0,\underline{\textcolor{red}{Cdaudio.SYS}}) (0,\underline{\textcolor{red}{Sfloppy.SYS}}) }; \addplot [fill=green!30,draw=green, postaction={pattern=north east lines}] coordinates { (20324,\underline{\textcolor{green}{kmixer.sys}}) (20145,\underline{\textcolor{green}{drmkaud.sys}}) (20142,\underline{\textcolor{green}{DMusic.sys}}) (20141,\underline{\textcolor{green}{aec.sys}}) (20139,\underline{\textcolor{green}{swmidi.sys}}) (20132,\underline{\textcolor{green}{splitter.sys}}) (19881,\underline{\textcolor{green}{Serial.SYS}}) (19880,\underline{\textcolor{green}{Parport.SYS}}) (9,\underline{\textcolor{green}{imapi.sys}}) (9,\underline{\textcolor{green}{redbook.sys}}) (8,\underline{\textcolor{green}{intelppm.sys}}) (1,\underline{\textcolor{green}{Cdaudio.SYS}}) (0,\underline{\textcolor{green}{Sfloppy.SYS}}) (0,\underline{\textcolor{green}{Flpydisk.SYS}}) (0,\underline{\textcolor{green}{Fdc.SYS}}) }; \legend{Infected memory image, Baseline memory image} \end{axis} \end{tikzpicture} } % End of \scalebox \caption{Timeline depicting unloaded kernel drivers (modules) from both memory images.} \end{figure} \end{document} It would be great if someone could help me. Thanks in advance.

  • How can I remove the Labels of the blue dots on the left plot and change the position of label nr16 in the right plot?
    by dan1365 on March 30, 2023 at 9:46 am

    \documentclass[11pt]{report} \usepackage{pgfplots, pgfplotstable} \pgfplotsset{width=10cm,compat=1.18} \usepackage{graphicx} \usepackage{caption} \usepackage{subcaption} \begin{document} \begin{figure} \centering \begin{subfigure}[tb]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[height=7cm, width=\linewidth, xlabel={}, ylabel={}, ytick={0,500,...,1700}, xtick={0,500,...,1700}, ymin=-170, ymax=1700, xmin=-170, xmax=1700, ymajorgrids, xmajorgrids] \addplot[ scatter/classes={0={blue}, 1={red}}, scatter, mark=*, only marks, scatter src=explicit symbolic, nodes near coords*={\Label}, visualization depends on={value \thisrow{label} \as \Label} %<- added value ] table [meta=class] { x y class label 0.3788 8.1653 0 - 6.3716 4.0196 0 - 0.4225 0.1447 0 - 14.8118 6.6124 0 - 2.7433 2.544 0 - 152.0046 30.6336 1 5 1375 428.5714 1 6 20.51 5.1280 0 - 38.8548 1492.8425 1 8 0.1409 0.000196 0 - }; \end{axis} \end{tikzpicture} \caption{} \label{} \end{subfigure}\hfill \begin{subfigure}[tb]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[height=7cm, width=\linewidth, xlabel={}, ylabel={}, ytick={0,2,...,10}, xtick={0,5,...,20}, ymin=-1.133, ymax=11.333, xmin=-2.266, xmax=22.666, ymajorgrids, xmajorgrids] \addplot[ scatter/classes={0={blue}, 1={red}}, scatter, mark=*, only marks, scatter src=explicit symbolic, nodes near coords*={\Label}, visualization depends on={value \thisrow{label} \as \Label} %<- added value ] table [meta=class] { x y class label 0.3788 8.1653 0 9 6.3716 4.0196 0 10 0.4225 0.1447 0 12 14.8118 6.6124 0 13 2.7433 2.544 0 14 20.51 5.1280 0 15 0.1409 0.000196 0 16 }; \end{axis} \end{tikzpicture} \caption{} \label{} \end{subfigure}\hfill \caption{} \end{figure} \end{document} > Blockquote

  • How to auto size pgfplots legend in beamer's overlays?
    by facetus on February 13, 2023 at 7:06 am

    I would like to gradually add plots to a graph using slide overlays. I figured how to do it. However, the legend doesn't behave the way I want. pgfplots sets the size of the legend box the same on all slides, equal to its maximum. IMHO it looks ugly on the first slides. Consider the following MWE \documentclass{beamer} \usepackage{fontspec} \usepackage{unicode-math} \usepackage{tikz} \usepackage{pgfplots} \setmainfont{Libertinus Serif} \setsansfont{Libertinus Sans} \usepgfplotslibrary{colorbrewer} \pgfplotsset{ compat = 1.18 , cycle list/Dark2-8 } \usetikzlibrary{overlay-beamer-styles} \begin{document} \begin{frame}{Test} \begin{figure} \centering \begin{tikzpicture} \pgfplotsset{ width = \textwidth , height = 0.7\textwidth , grid = major , every axis plot/.append style = { line width = 1.5pt , no markers , domain = 0:1 , samples = 500 } } \begin{axis}[ xmin = 0 , xmax = 1 , legend style = { anchor = north west , at = {(0.05, 0.95)} , font = \scriptsize } , legend cell align = {left} ] \addplot+ coordinates { (0, 0) (0.45, 0) (0.55, 1) (1, 1) }; \addlegendentry{1} \addplot+[ samples = 2 , visible on = <2->]{-0.135557 + 1.27111 * x}; \addlegendentry[visible on = <2->]{a long legend line} \addplot+[visible on = <3->] {0.0734743 - 2.49145 * x + 10.0335 * x^2 - 6.68901 * x^3}; \addlegendentry[visible on = <3->]{3} \end{axis} \end{tikzpicture} \end{figure} \end{frame} \end{document} Here is how the chart on the first slide looks like: I would want this: Then this: and so on...

  • Fill in between polar curves
    by user3303069 on April 26, 2015 at 8:14 pm

    I am trying to fill in space between a pair of spiral curves in tikz. I have tried using the fillbetween library but it just shades in the whole spiral. Does anyone have a hint they could offer? Thanks. \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{fillbetween} \usepgfplotslibrary{polar} \begin{document} \begin{tikzpicture}[scale=0.5] \begin{polaraxis}[hide axis] \addplot [mark=none,domain=0:720,samples=600,thick,gray] {0.5*x}; \addplot [mark=none,domain=0:720-180,samples=600,thick,gray] {-0.667*x}; %\addplot [mark=none,domain=0:720,samples=600,thick,gray] {-0.5*x}; %\addplot [mark=none,domain=0:720-180,samples=600,thick,gray] {0.667*x}; \end{polaraxis} \end{tikzpicture} \end{document}

  • Plotting a distribution with tikz package
    by Colenso on October 8, 2014 at 7:30 am

    I'm trying to generate a plot of a censored Gamma distribution. I've managed to make the plot of the Gamma-pdf and reference the censoring point, but I'm failing to suppress anything beyond it. In other words, after the censoring point n-star there should be no distribution diagram. My strategy was to try to fill the distribution's plot beyond n-star in white. I made the filling border thick and while it helped it didn't get the job done (you can still see a thin line beyond n-star). I'm attaching an image of the generated plot and also pasting the code. I would appreciate any ideas that could solve this problem. Many thanks! \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture}[ declare function={gamma(\z)= 2.506628274631*sqrt(1/\z)+ 0.20888568*(1/\z)^(1.5)+ 0.00870357*(1/\z)^(2.5)- (174.2106599*(1/\z)^(3.5))/25920- (715.6423511*(1/\z)^(4.5))/1244160)*exp((-ln(1/\z)-1)*\z;}, declare function={gammapdf(\x,\k,\theta) = 1/(\theta^\k)*1/(gamma(\k))*\x^(\k-1)*exp(-\x/\theta);} ] \begin{axis}[ no markers, domain=0:9, samples=100, axis lines=left, xlabel=$n_t^i$, ylabel=$f_n(.)$, every axis y label/.style={at=(current axis.above origin),anchor=east}, every axis x label/.style={at=(current axis.right of origin),anchor=north}, height=5cm, width=9cm, xtick={6.0}, ytick=\empty, xticklabels={$n^*$}, %xticklabels={$\bar n (\theta_t)$}, enlargelimits=false, clip=false, axis on top, grid = major ] \addplot [very thick,cyan!20!black,domain=0:20] {gammapdf(x,2,2)}; \addplot [fill=cyan!20, draw=none, domain=0:6.0] {gammapdf(x,2,2)} \closedcycle; \addplot [very thick, fill=white!20!white, draw=none, domain=6.01:20] {gammapdf(x,2,2)} \closedcycle; \end{axis} \end{tikzpicture} \end{document}