pgfplots
- \tikzmath defined functions sometimes won't parse in \addplot, producing spurious errorsby Francis Cook on November 13, 2025 at 12:38 pm
This is my first post so the graph may not appear and/or the format may look weird. Apologies if that is so. The graph is produced when the line \addplot[red, thick] {myexp(x,4)}; is commented out When included, numerous errors result, seemingly spurious because it is not being parsed as expected, for example "! Illegal unit of measure (pt inserted)." Unfortunately, I cannot see my mistake. I have tried everything I can think of, including spaces before and/or after pretty much every reference and even trying to use "declare function" (but I couldn't make that work the with complex, iterative logic). I am puzzled by the fact that a simple, two argument function (myfunc) can be called successfully, one with more complex logic (expterm) can be called successfully, but a complex one, with a loop and calls (myexp) fails. Any help/suggestions gratefully received. I am hoping to fix this with \tikzmath rather than use the equivalent pgfplots function definitions etc The code is as follows \documentclass{article} \usepackage{pgfplots} \usetikzlibrary{math} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} % Define the function using tikzmath - scope is within the tikzpicture % note that the \tikzmath block is sensitive to blank lines % so don't leave any lines blank % inclde non math lines like drawing commands within double curly braces {{ }} \tikzmath{ function myfunc(\x,\a) { return sin(\x r) + \a*\x; }; function expterm(\x,\n) { if \n == 0 then { return 1; } else { if \n == 1 then { return \x; } else { return \x ^ \n / factorial(\n); }; }; }; function myexp(\x,\n) { \s=0; for \i in {0,1,...,\n-1}{ \s=\s+expterm(\x,\i); }; return \s; }; } \begin{axis}[ domain=-2*pi:2*pi, xmin=-2*pi, xmax=2*pi, ymin=-3, ymax=3, restrict y to domain=-3:3, samples=100, axis lines=middle, xtick={ -2*pi, -3*pi/2, -pi, -pi/2, pi/2, pi, 3*pi/2, 2*pi }, xticklabels={ $-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $-\frac{\pi}{2}$, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$ }, width=14cm, height=14cm, xlabel=$x$, ylabel={$y = f(x)$}, title={Function defined in \texttt{\textbackslash tikzmath}} ] % Use the tikzmath function in an addplot \addplot[blue, thick] {myfunc(x,0.3)}; \addplot[green, thick] {expterm(x,3)}; % \addplot[red, thick] {myexp(x,4)}; \end{axis} \end{tikzpicture} \end{document}
- Why does PGFPlots separate the axes of my log-log graph?by Rain on November 12, 2025 at 6:53 pm
I'm trying to make a log-log graph. Semi-log graphs and linear graphs work just fine, but for some reason when I try to make a log-log graph PGFPlots doesn't draw the horiziontal axis or the curve. MWE: \documentclass[11pt,a4paper]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.9} \begin{document} \begin{tikzpicture} \begin{loglogaxis}[ xmin=10, xmax=40, axis x line=middle, xlabel=$x$, ymin=10, ymax=50, axis y line=center, ylabel=$y$, disabledatascaling ] \addplot[smooth,thick,blue,domain=10:40,samples=51]coordinates{ (10,10) (20,30) (30,20) (40,42) }; \end{loglogaxis} \end{tikzpicture} \end{document} Result: Scale has nothing to do with it. I get the same problem if I set the axis ranges to, say, (1e8,1e12). Thanks in advance for any help.
- Aligning arrows along a path at fixed steps on a rectangular gridby PatrickT on November 11, 2025 at 5:42 pm
The objective is to have arrows along a path for every 1-unit step we take horizontally or vertically. The arrows would be aligned midway between major grid tick marks, e.g. midway along (0,0)--(0,1). To give context, these arrows could be used to show east-west and north-west movement along a rectangular grid. I have managed to handle the case where the x and y units are the same. Below I have tweaked the parameters to have the blue arrows aligned at the midpoint (grid minor line colored in cyan). But I failed with the red arrows. The problem is that the x-scale and y-scale are quite different. If the step is tweaked to match horizontal distances (parallel to the x-axis), then it will not match the vertical distances. How to fix this? To clarify, if I give a path like (0,0)--(10,0), I would like an arrow midway along (0,0)--(1,0), then midway along (1,0)--(2,0), and so on. Otherwise I would just use something like [midway](0,0)--(10,0) or [pos=0.5](0,0)--(10,0). In my code I have to tweak the "starting value" as well as the "step". It would obviously be much nicer to have a solution where I could set a starting value at 0.5 (meaning at the midway point between two major grid tick lines) and a step equal to 1 (meaning moving by 1 unit of image scale --- not units of the axis --- along both x and y directions). \documentclass[border=3pt,tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{calc} % Required for coordinate calculations \usetikzlibrary{decorations.markings} % Required for decorations along path % Define a TikZ style for arrows on path: color as optional argument % \usetikzlibrary{decorations.markings, arrows.meta} \tikzset{ arrows along path/.style args={#1/#2/#3}{% >=latex, decoration={ markings, mark=between positions #1 and #2 step #3 with { \arrow{latex} } }, postaction={decorate} }, arrows along path/.default={0/1/0.5} } % x has range 5 % y has range 3000 % 3000/5 = 600 % 5/3000 = 0.00166666666 \begin{document} \begin{tikzpicture} \begin{axis}[ x = 2cm, y = 0.0033cm,% tweaked to match y/x=5/3000 ratio xmin=0, xmax=5, ymin=500, ymax=3500, xtick = {0,1,...,5}, ytick = {500,1000,...,3500}, tick align=outside, minor tick num=1, minor tick length=4pt, minor tick style={color=cyan,thick}, minor grid style={color=cyan,thick}, grid = both, clip = false, ] \coordinate (A) at (0,2000); \coordinate (B) at (5,2000); \coordinate (C) at (0,1000); \coordinate (D) at (1,1000); \coordinate (E) at (1,3000); \coordinate (F) at (4,3000); \coordinate (G) at (4,1000); \coordinate (H) at (5,1000); % Blue line \draw [blue, thick, arrows along path={0.118/1/0.20}] (A) -- (B); % Red line \draw [red, thick, arrows along path={0.051/1/0.079}] (C) -- (D) -- (E) -- (F) -- (G) -- (H); \end{axis} \end{tikzpicture} \end{document} Second implementation, also fails to get the correct output: \documentclass[border=3pt,tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{calc} % Required for coordinate calculations \usetikzlibrary{decorations.markings} % Required for decorations along path % Define a TikZ style for arrows on path: color as optional argument % \usetikzlibrary{decorations.markings, arrows.meta} \tikzset{ arrows along path/.style args={#1/#2/#3}{% >=latex, decoration={ markings, mark=between positions #1 and #2 step #3 with { \arrow{latex} } }, postaction={decorate} }, arrows along path/.default={0/1/0.5} } \begin{document} \begin{tikzpicture} \begin{axis}[ x=2cm, y=0.0033cm, xmin=0, xmax=5, ymin=500, ymax=3500, xtick = {0,1,...,5}, ytick = {500,1000,...,3500}, tick align=outside, minor tick num=1, minor tick length=4pt, minor tick style={color=cyan,thick}, minor grid style={color=cyan,thick}, grid = both, clip = false, ] \coordinate (A) at (0,2000); \coordinate (B) at (5,2000); \coordinate (C) at (0,1000); \coordinate (D) at (1,1000); \coordinate (E) at (1,3000); \coordinate (F) at (4,3000); \coordinate (G) at (4,1000); \coordinate (H) at (5,1000); % Blue line \draw [blue, thick, arrows along path={0.12/1/0.20}] (A) -- (B); % Red line \pgfplotsextra{ \foreach \P/\Q in {C/D, D/E, E/F, F/G, G/H}{ \draw [red, thick, arrows along path={0.6/1/0.40}] (\P) -- (\Q); } } \end{axis} \end{tikzpicture} \end{document} A variant with a node and a dot, that sort of look like the ideal implementation for its simplicity, but fails just the same. \documentclass[border=3pt,tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{calc} % Required for coordinate calculations \usetikzlibrary{decorations.markings} % Required for decorations along path % set up all axes \pgfplotsset{% every axis/.append style={% axis styles %ticks = none, grid = both, clip = false,% remove clip }% }% % Define a TikZ style for arrows \tikzset{ marks along path/.style args={#1/#2/#3/#4}{% decoration={ markings, mark=between positions #1 and #2 step #3 with { \node[#4] at (0,0) {}; } }, postaction={decorate} }, marks along path/.default={0/1/0.5/shape=circle,fill=black,draw=black,inner sep=0pt,minimum size=4mm,line width=2pt} } \begin{document} \begin{tikzpicture} \begin{axis}[ x = 2cm, y = 0.0033cm,% tweaked to match y/x=5/3000 ratio xmin=0, xmax=5, ymin=500, ymax=3500, xtick = {0,1,...,5}, ytick = {500,1000,...,3500}, tick align=outside, minor tick num=1, minor tick length=4pt, minor tick style={color=cyan,thick}, minor grid style={color=cyan,thick}, grid = both, clip = false, ] \coordinate (A) at (0,2000); \coordinate (B) at (5,2000); \coordinate (C) at (0,1000); \coordinate (D) at (1,1000); \coordinate (E) at (1,3000); \coordinate (F) at (4,3000); \coordinate (G) at (4,1000); \coordinate (H) at (5,1000); % Blue line \draw[blue, line width=2pt, marks along path={0/1/0.5/shape=circle,fill=blue,draw=black}] (A) -- (B); \draw[red, line width=2pt, marks along path={0/1/0.5/shape=circle,fill=red,draw=black}] (C) -- (D) -- (E) -- (F) -- (G) -- (H); \end{axis} \end{tikzpicture} \end{document}
- Plotting quasi-3D figure with axial filled planesby katang on November 11, 2025 at 4:10 pm
I want to make a quasi-3D figure from three variables. They pair-wise form a two-dimensional figure. I want to emphasize that the green plot is in the green plane, etc. I have two issues 1./ The red and green planes are OK, but the blue plane is squeezed to a line 2./ The opacity does not work as I expected What did I do wrong? (3./ A better idea to illustrate what I want?) \documentclass[border=5mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.13} \usetikzlibrary{backgrounds} \definecolor{webblue}{rgb}{0,0,.8} \definecolor{webgreen}{rgb}{0, 0.5, 0} % less intense green \definecolor{webred}{rgb}{0.5, 0, 0} % less intense red \begin{filecontents*}{data.csv} a,b,c,d,e,f,g,h,i,j,k 0.001,0.180,0.000,0.000,0.000,179.563,1,0.000, 0.003,0.528,0.000,0.000,2.565,174.248,1,0.147, 0.007,1.184,0.000,0.000,7.544,163.879,1,0.431, 0.015,2.337,0.000,0.000,16.908,144.160,1,0.967, 0.031,2.613,0.000,0.000,33.384,276.050,1,1.908, 0.033,3.147,0.000,0.000,37.327,267.271,1,2.134, 0.037,4.148,0.000,0.000,44.964,250.157,1,2.570, 0.045,4.547,0.000,0.000,59.258,398.610,1,3.388, 0.047,5.318,0.000,0.000,64.953,385.747,1,3.713, 0.051,6.761,0.000,0.000,75.974,360.676,1,4.343, 0.059,9.266,0.000,0.000,96.584,313.078,1,5.521, 0.067,11.279,0.000,0.000,132.364,251.728,1,7.567, 0.075,11.654,0.000,0.000,161.133,374.187,1,9.211, 0.077,12.374,0.000,0.000,166.479,360.293,1,9.517, 0.081,13.707,0.000,0.000,176.773,333.243,1,10.106, 0.089,15.963,0.000,0.000,195.815,282.019,1,11.194, 0.097,17.718,0.000,0.000,228.046,219.302,1,13.037, 0.113,19.926,0.000,0.000,253.109,138.008,1,14.469, 0.129,20.822,0.000,0.000,284.654,56.022,1,16.273, 0.130,24.281,3.978,3756.321,297.459,3458.862,0,17.005, 0.131,27.647,7.913,3713.080,346.871,3366.209,0,19.829, 0.132,30.923,11.804,3670.273,394.960,3275.313,0,22.579, 0.133,34.109,15.653,3627.897,441.750,3186.147,0,25.253, 0.134,37.207,19.460,3585.946,487.267,3098.679,0,27.855, 0.135,40.220,23.224,3544.416,531.533,3012.883,0,30.386, 0.136,43.149,26.948,3503.303,574.575,2928.729,0,32.847, 0.137,45.995,30.631,3462.604,616.414,2846.190,0,35.238, 0.138,48.760,34.273,3422.313,657.073,2765.240,0,37.563, 0.139,51.446,37.875,3382.428,696.577,2685.851,0,39.821, 0.140,54.054,41.438,3342.943,734.946,2607.997,0,42.014, 0.141,56.586,44.961,3303.855,772.203,2531.652,0,44.144, 0.142,59.043,48.446,3265.160,808.370,2456.790,0,46.212, 0.143,61.426,51.892,3226.854,843.467,2383.387,0,48.218, 0.144,63.737,55.300,3188.933,877.515,2311.418,0,50.165, 0.145,65.978,58.671,3151.394,910.535,2240.858,0,52.052, 0.146,68.150,62.005,3114.232,942.548,2171.684,0,53.882, 0.147,70.254,65.302,3077.444,973.572,2103.872,0,55.656, 0.148,72.291,68.562,3041.026,1003.627,2037.399,0,57.374, 0.149,74.264,71.786,3004.975,1032.733,1972.242,0,59.038, 0.151,78.010,78.128,2933.957,1060.908,1873.050,0,60.649, 0.153,81.510,84.331,2864.363,1114.423,1749.940,0,63.708, 0.155,84.773,90.397,2796.163,1164.422,1631.742,0,66.566, 0.157,87.810,96.328,2729.332,1211.043,1518.289,0,69.231, 0.159,90.628,102.129,2663.840,1254.422,1409.418,0,71.711, 0.161,93.238,107.802,2599.663,1294.691,1304.972,0,74.013, 0.163,95.648,113.348,2536.775,1331.976,1204.798,0,76.145, 0.165,97.865,118.772,2475.149,1366.399,1108.750,0,78.112, 0.167,99.899,124.075,2414.762,1398.078,1016.685,0,79.923, 0.169,101.756,129.261,2355.590,1427.126,928.464,0,81.584, 0.173,104.904,139.287,2240.791,1453.653,787.137,0,83.101, 0.177,107.432,148.871,2130.568,1498.633,631.936,0,85.672, 0.181,109.392,158.029,2024.744,1534.743,490.001,0,87.736, 0.189,111.495,175.141,1825.613,1562.743,262.869,0,89.337, 0.197,111.890,190.756,1642.107,1592.786,49.321,0,91.054, 0.213,107.391,217.966,1317.289,1598.422,-281.134,0,91.376, 0.221,104.509,229.776,1173.854,1534.163,-360.310,0,87.703, 0.229,100.899,240.517,1041.785,1492.985,-451.200,0,85.349, 0.237,96.730,250.275,920.210,1441.419,-521.210,0,82.401, 0.241,94.655,254.812,863.102,1381.853,-518.750,0,78.996, 0.245,92.479,259.131,808.320,1352.210,-543.889,0,77.301, 0.249,90.218,263.244,755.773,1321.130,-565.358,0,75.525, 0.253,87.884,267.158,705.371,1288.824,-583.453,0,73.678, 0.257,85.490,270.882,657.031,1255.484,-598.453,0,71.772, 0.261,83.048,274.423,610.670,1221.286,-610.616,0,69.817, 0.265,80.567,277.789,566.212,1186.394,-620.182,0,67.822, 0.269,78.057,280.987,523.581,1150.955,-627.374,0,65.796, 0.273,75.528,284.025,482.704,1115.105,-632.402,0,63.747, 0.277,72.986,286.908,443.511,1078.968,-635.457,0,61.681, 0.281,70.439,289.644,405.937,1042.656,-636.719,0,59.605, 0.285,67.894,292.238,369.916,1006.272,-636.356,0,57.525, 0.289,65.356,294.697,335.388,969.909,-634.521,0,55.446, 0.293,62.830,297.025,302.292,933.651,-631.359,0,53.374, 0.297,60.322,299.229,270.571,897.573,-627.002,0,51.311, 0.301,57.836,301.314,240.171,861.744,-621.573,0,49.263, 0.305,55.375,303.284,211.040,826.226,-615.186,0,47.233, 0.309,52.943,305.144,183.125,791.072,-607.947,0,45.223, 0.313,50.543,306.899,156.379,756.332,-599.954,0,43.237, 0.317,48.178,308.553,130.754,722.049,-591.295,0,41.277, 0.321,45.850,310.111,106.207,688.261,-582.054,0,39.346, 0.325,43.561,311.576,82.693,655.001,-572.308,0,37.444, 0.329,41.312,312.952,60.171,622.298,-562.127,0,35.575, 0.333,39.106,314.244,38.601,590.176,-551.575,0,33.738, 0.337,36.943,315.454,17.945,558.657,-540.712,0,31.937, 0.341,34.825,316.586,-1.833,527.760,-529.593,0,30.170, 0.345,32.752,317.643,-20.770,497.497,-518.267,0,28.440, 0.349,30.725,318.629,-38.899,467.882,-506.781,0,26.747, 0.353,28.744,319.546,-56.253,438.923,-495.176,0,25.092, 0.361,24.749,321.186,-88.759,410.627,-499.386,0,23.474, 0.369,20.972,322.584,-118.525,353.554,-472.079,0,20.212, 0.377,17.409,323.761,-145.767,299.603,-445.369,0,17.127, 0.379,16.994,323.761,-152.207,248.703,-414.874,1,14.218, 0.381,16.162,323.761,-158.505,242.776,-416.267,1,13.879, 0.385,14.488,323.761,-170.686,230.883,-418.554,1,13.199, 0.393,11.118,323.761,-193.467,206.966,-421.244,1,11.832, 0.401,7.937,323.761,-214.281,158.823,-397.523,1,9.079, 0.409,4.941,323.761,-233.285,113.392,-374.496,1,6.482, 0.417,2.124,323.761,-250.623,70.593,-352.238,1,4.036, 0.425,-0.523,323.761,-266.428,30.337,-330.805,1,1.734, 0.433,-3.005,323.761,-280.823,-7.469,-310.237,1,-0.427, 0.441,-5.329,323.761,-293.922,-42.925,-290.557,1,-2.454, 0.449,-7.503,323.761,-305.828,-76.131,-271.776,1,-4.352, 0.457,-9.535,323.761,-316.637,-107.192,-253.896,1,-6.128, 0.465,-11.430,323.761,-326.438,-136.208,-236.910,1,-7.787, 0.481,-15.123,323.761,-343.332,-163.284,-230.797,1,-9.334, 0.497,-18.249,323.761,-357.086,-216.037,-195.389,1,-12.350, 0.513,-20.889,323.761,-368.187,-260.698,-164.995,1,-14.903, 0.529,-23.112,323.761,-377.048,-298.411,-138.927,1,-17.059, 0.545,-24.977,323.761,-384.017,-330.166,-116.585,1,-18.874, 0.577,-28.284,323.761,-393.420,-356.814,-103.345,1,-20.398, 0.593,-29.254,323.761,-396.315,-404.057,-60.619,1,-23.099, 0.625,-30.933,323.761,-399.392,-417.913,-52.457,1,-23.891, 0.657,-31.917,323.761,-399.750,-441.893,-30.752,1,-25.262, 0.689,-32.445,323.761,-398.191,-455.951,-16.499,1,-26.065, 0.721,-32.668,323.761,-395.292,-463.494,-6.977,1,-26.496, 0.753,-32.685,323.761,-391.462,-466.683,-0.527,1,-26.679, 0.785,-32.560,323.761,-386.996,-466.924,3.892,1,-26.692, 0.817,-32.338,323.761,-382.102,-465.145,6.940,1,-26.591, 0.849,-32.048,323.761,-376.930,-461.972,9.050,1,-26.409, 0.881,-31.712,323.761,-371.585,-457.835,10.506,1,-26.173, 0.913,-31.344,323.761,-366.142,-453.032,11.503,1,-25.898, 0.945,-30.955,323.761,-360.656,-447.774,12.174,1,-25.598, 0.977,-30.551,323.761,-355.164,-442.208,12.611,1,-25.280, 1.009,-30.139,323.761,-349.693,-436.444,12.879,1,-24.950, 1.041,-29.722,323.761,-344.262,-430.556,13.025,1,-24.613, 1.073,-29.304,323.761,-338.882,-424.602,13.082,1,-24.273, 1.105,-28.885,323.761,-333.564,-418.622,13.074,1,-23.931, 1.137,-28.469,323.761,-328.313,-412.645,13.019,1,-23.590, 1.169,-28.055,323.761,-323.133,-406.693,12.930,1,-23.249, 1.201,-27.645,323.761,-318.026,-400.782,12.816,1,-22.911, 1.233,-27.239,323.761,-312.994,-394.924,12.684,1,-22.576, 1.265,-26.838,323.761,-308.037,-389.125,12.539,1,-22.245, 1.297,-26.441,323.761,-303.156,-383.393,12.385,1,-21.917, 1.329,-26.050,323.761,-298.350,-377.731,12.225,1,-21.594, 1.361,-25.664,323.761,-293.618,-372.143,12.061,1,-21.274, 1.393,-25.283,323.761,-288.961,-366.629,11.895,1,-20.959, 1.425,-24.908,323.761,-284.376,-361.191,11.727,1,-20.648, 1.457,-24.538,323.761,-279.864,-355.831,11.559,1,-20.342, 1.489,-24.174,323.761,-275.423,-350.546,11.391,1,-20.040, 1.521,-23.815,323.761,-271.052,-345.339,11.225,1,-19.742, 1.553,-23.461,323.761,-266.750,-340.208,11.059,1,-19.449, 1.585,-23.112,323.761,-262.516,-335.152,10.895,1,-19.160, 1.617,-22.769,323.761,-258.350,-330.171,10.733,1,-18.875, 1.649,-22.430,323.761,-254.249,-325.265,10.573,1,-18.594, 1.681,-22.097,323.761,-250.214,-320.432,10.414,1,-18.318, 1.713,-21.769,323.761,-246.242,-315.671,10.258,1,-18.046, 1.745,-21.445,323.761,-242.334,-310.982,10.103,1,-17.778, 1.777,-21.127,323.761,-238.487,-306.363,9.951,1,-17.514, 1.809,-20.813,323.761,-234.702,-301.814,9.801,1,-17.254, 1.841,-20.504,323.761,-230.977,-297.333,9.653,1,-16.998, 1.873,-20.200,323.761,-227.311,-292.920,9.508,1,-16.745, 1.905,-19.901,323.761,-223.703,-288.574,9.364,1,-16.497, 1.937,-19.605,323.761,-220.152,-284.293,9.223,1,-16.252, 1.969,-19.315,323.761,-216.657,-280.077,9.083,1,-16.011, \end{filecontents*} \pgfplotscreateplotcyclelist{my color list}{ solid, color=webblue, every mark/.append style={solid, fill=webblue}, no marks\\% densely dashdotted, color=webred, every mark/.append style={solid, fill=webred},no marks\\% densely dotted, thick, color=webgreen, every mark/.append style={solid, fill=webgreen}, no marks%mark=triangle* \\% } \begin{document} \begin{tikzpicture} \begin{axis} [ axis lines=center,view={15}{25}, xlabel={$t$}, ylabel=$V_M$,zlabel=$\frac{dV}{dt}$, xtick={1}, ytick=100, y label style={at={(axis description cs:0.25,.5)}, anchor=south}, cycle list name={my color list}, z label style={at={(axis description cs:-0.06,.7)}, anchor=west}, cycle list name={my color list}, ] \addplot3+ table [x=a, y=b, z expr=0,col sep=comma, no marks] {data.csv}; \addplot3+ table [x=a, z=d, y expr=0, col sep=comma] {data.csv}; \addplot3+ table [y=b, z=d, x expr=0, col sep=comma] {data.csv}; \begin{scope}[on background layer] \addplot3 [fill=webgreen!20,opacity=30,draw=none] coordinates {(0,-40,3900)(0,120,3900)} \closedcycle; \addplot3 [fill=webgreen!20,draw=none] coordinates {(0,-40,-1200)(0,120,-1200)} \closedcycle; \addplot3 [fill=red!10,opacity=30,draw=none] coordinates {(0,0,3900)(2,0,3900)} \closedcycle; \addplot3 [fill=red!10,draw=none] coordinates {(0,0,-1200)(2,0,-1200)} \closedcycle; \addplot3 [fill=blue!30,draw=none] coordinates {(2,-40,0)(2,120,0)} \closedcycle; \addplot3 [fill=blue!30,draw=none] coordinates {(1,-40,0)(1,120,0)} \closedcycle; \end{scope} \end{axis} \end{tikzpicture} \end{document}
- Plot any real sequence of real variables as in Geogebra and Desmosby Sebastiano on November 8, 2025 at 11:25 pm
Several years ago, I created a GeoGebra script to plot any real sequence of real variables. As you can see from the screenshot, there is a command on the left: Sequence({(n, 1/n)}, n, 1, M) which putting every sequence, give me a graph of this. Usually, I use GeoGebra and then quickly export to TikZ with the option Save as. Here an example: \documentclass[10pt]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.15} \usepackage{mathrsfs} \usetikzlibrary{arrows} \pagestyle{empty} \begin{document} \definecolor{qqweqq}{rgb}{0,0.43137254901960786,0} \definecolor{aqaqaq}{rgb}{0.6274509803921569,0.6274509803921569,0.6274509803921569} \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm] \begin{axis}[ x=1cm,y=1cm, axis lines=middle, grid style=dashed, xmin=-0.41753528626111724, xmax=22.657576260984815, ymin=-1.2286763992422356, ymax=7.280825323814707, xtick={0,1,...,22}, ytick={-1.2000000000000002,-1.1,...,7.200000000000001},] \clip(-0.41753528626111724,-1.2286763992422356) rectangle (22.657576260984815,7.280825323814707); \draw[line width=5.2pt,color=aqaqaq] (5.616473767760089,4.363281875909468) -- (10.036993221255479,4.363281875909468); \draw (11.053712695559419,5.777848396105947) node[anchor=north west] {$a_n= \frac{1}{n} \quad \quad n \in [1,14]$}; \begin{scriptsize} \draw [fill=aqaqaq] (7.598085936568367,4.363281875909468) circle (3pt); \draw[color=aqaqaq] (8.158272453519938,5.114770339763847) node {$M = 14$}; \draw [fill=qqweqq] (1,1) circle (1.5pt); \draw [fill=qqweqq] (2,0.5) circle (1.5pt); \draw [fill=qqweqq] (3,0.3333333333333333) circle (1.5pt); \draw [fill=qqweqq] (4,0.25) circle (1.5pt); \draw [fill=qqweqq] (5,0.2) circle (1.5pt); \draw [fill=qqweqq] (6,0.16666666666666666) circle (1.5pt); \draw [fill=qqweqq] (7,0.14285714285714285) circle (1.5pt); \draw [fill=qqweqq] (8,0.125) circle (1.5pt); \draw [fill=qqweqq] (9,0.1111111111111111) circle (1.5pt); \draw [fill=qqweqq] (10,0.1) circle (1.5pt); \draw [fill=qqweqq] (11,0.09090909090909091) circle (1.5pt); \draw [fill=qqweqq] (12,0.08333333333333333) circle (1.5pt); \draw [fill=qqweqq] (13,0.07692307692307693) circle (1.5pt); \draw [fill=qqweqq] (14,0.07142857142857142) circle (1.5pt); \end{scriptsize} \end{axis} \end{tikzpicture} \end{document} With Desmos, for example, there is a page where https://www.desmos.com/calculator/4wwz1emgyd?lang=it I have given an arbitrary sequence a(x)= sin ( (π/2) ⋅ x⁴/(x⁴+1)) it gives a graph. Is it possible to have the same thing of Geogebra and Desmos in TikZ/Metapost/Lua that allow me to plot any sequence directly to save time without to write a long code?
- Iterated plot with TikZ, PGFPlots and foreach loopby Dominique on November 5, 2025 at 4:31 pm
I'm trying to plot an illustration of the fixed point method in which a function is evaluated repeatedly in a loop. The result should be a staircase or spiral plot on top of the plot of the function itself. I've read here about the use of \edef inside a foreach loop. The following MWE should show what I'm trying to do, but it seems to only perform a single iteration. Notes: the loop variable isn't used inside the loop. perhaps it's an illusion that only single iteration is performed and the real issue is that \xprev and \xnext aren not updated at each pass through the loop. I tried placing the updates inside the \edef, but that gives an undefined control sequence error. I also tried \pgfplotsinvokeforeach instead of \foreach, but only obtained other errors. \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \pgfmathdeclarefunction{g}{1}{\pgfmathparse{#1^2 - 2}} \begin{tikzpicture} \begin{axis} [ xmin = -2.5, xmax = 2.5, ymin = -3, ymax = 3, axis x line = center, axis y line = center, domain=-2.5:2.5, samples=300, ] \addplot[ultra thick] {g(x)}; % graph of g \addplot[thin] {x}; % diagonal \def\xstart{-0.75} \pgfmathsetmacro{\xprev}{\xstart}; \pgfmathsetmacro{\xnext}{g(\xprev)}; \draw[thick, blue] (\xstart, 0) -- (\xstart, \xnext) -- (\xnext, \xnext); \foreach \i in {1, 2, 3}{ \pgfmathsetmacro{\xprev}{\xnext} \pgfmathsetmacro{\xnext}{g(\xprev)} % x <- g(x) \edef\plotoneiter{% \noexpand% \draw[thick, blue] ({\xprev}, {\xprev}) -- ({\xprev}, {\xnext}) -- ({\xnext}, {\xnext}); }\plotoneiter% } \end{axis} \end{tikzpicture} \end{document} Thanks in advance for any hints! EDIT: Here is a quick sketch of what I'm trying to achieve:
- Problem trying to set color in dynamic in pgfplot [duplicate]by Liam Seddio on November 2, 2025 at 6:12 pm
I'm trying to draw 10 functions of ten different colors (actually starting from red and ending with yellow) inside a tikzpicture environment. Problem is that the code reads only the first color (red) and then plot all 10 functions in green Here's the code: \documentclass{amsart} \usepackage[english]{babel} \usepackage{amsmath} \usepackage{hyperref} \usepackage[a4paper, margin=2.5cm]{geometry} \usepackage{pgfplots} \usepackage{xcolor} \pgfplotsset{compat=1.18} \usepackage{mdframed} \usepackage{subcaption} \begin{document} \begin{figure}[htb] \begin{mdframed} % un solo riquadro esterno per coerenza visiva \centering % --- PRIMA SUBFIGURE --- \begin{subfigure}[t]{0.45\textwidth} \centering \begin{tikzpicture} \begin{axis}[ axis lines=none, grid=none, width=\linewidth, height=0.8\linewidth, % stessa altezza per entrambi xmin=-1, xmax=4, ymin=-2, ymax=3, samples=200, domain=0:3.1416 ] \addplot[thick,smooth]{2*sin(deg(x))}; \addplot[only marks, mark=*] coordinates {(0,0)}; \addplot[only marks, mark=*] coordinates {(3.1416,0)}; \node[below left] at (axis cs:0,0) {$x_0$}; \node[below right] at (axis cs:3.1416,0) {$x_1$}; \node[below] at (axis cs:1.5,1.9) {$\gamma(t)$}; \end{axis} \end{tikzpicture} \end{subfigure}% \hfill % --- SECONDA SUBFIGURE --- \begin{subfigure}[t]{0.45\textwidth} \centering \begin{tikzpicture} \begin{axis}[ axis lines=none, grid=none, width=\linewidth, height=0.8\linewidth, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5, samples=200, domain=0:360 ] \addplot[thick, parametric] ({-0.5+0.5*cos(x)}, {0.5*sin(x)}); \addplot[only marks, mark=*] coordinates {(0,0)}; \node[right] at (axis cs:0,0) {$x_0$}; \node[left] at (axis cs:-1,0) {$\mu(t)$}; \end{axis} \end{tikzpicture} \end{subfigure} \hfill \begin{subfigure}[t]{0.45\textwidth} \centering \begin{tikzpicture} \begin{axis}[ axis lines=none, grid=none, width=\linewidth, height=0.8\linewidth, xmin=-1, xmax=4, ymin=-3, ymax=3, samples=200, domain=0:3.1416 ] \addplot[thick,smooth]{2*sin(deg(x))}; \addplot[thick,smooth]{-sin(deg(x))}; \addplot[only marks, mark=*] coordinates {(0,0)}; \addplot[only marks, mark=*] coordinates {(3.1416,0)}; \foreach \n in {1,...,9} { \pgfmathsetmacro{\t}{\n/10} \pgfmathsetmacro{\coef}{2 - 3*\t} \pgfmathtruncatemacro{\perc}{100*\t} \addplot[ smooth, thick, red!\perc!black, % gradiente dal verde al blu domain=0:3.1416, samples=200 ] {\coef*sin(deg(x))}; } \node[below left] at (axis cs:0,0) {$x_0$}; \node[below right] at (axis cs:3.1416,0) {$x_1$}; \node[above] at (axis cs:1.5,1.9) {$\gamma_0(t)$}; \node[below right] at (axis cs:2.5,-0.4) {$\gamma_1(t)$}; \end{axis} \end{tikzpicture} \end{subfigure} \hfill \begin{subfigure}[t]{0.45\textwidth} %is here in this subfigure the problem \centering \begin{tikzpicture} \begin{axis}[ axis lines=none, grid=none, width=\linewidth, height=0.8\linewidth, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5, samples=200, domain=0:360 ] \foreach \n in {1,...,9} { \pgfmathsetmacro{\t}{\n/10} \pgfmathsetmacro{\coefa}{-0.5 + 0.25*\t} \pgfmathsetmacro{\coefb}{-\coefa} \pgfmathtruncatemacro{\perc}{100*\t} \addplot[thick, parametric]({\coefa +\coefb*cos(x)},{\coefb*sin(x)}); }; \addplot[thick, parametric] ({-0.5+0.5*cos(x)}, {0.5*sin(x)}); \addplot[only marks, mark=*] coordinates {(0,0)}; \node[right] at (axis cs:0,0) {$x_0$}; \node[left] at (axis cs:-1,0) {$\mu_0(t)$}; \node[right] at (axis cs:-0.55,0) {$\mu_1(t)$}; \end{axis} \end{tikzpicture} \end{subfigure} \hfill \end{mdframed} \caption{Main Caption} \end{figure} \end{document} And the result is
- pgfplots: declare function and parameters globallyby PatrickT on November 1, 2025 at 12:11 am
As I was intent on moving function declarations further up, so as to use them in multiple files, I noticed something unexpected. The first code plots a thin black line. The second code plots thick blue dots. I asked a well-known LLM and got a plausible explanation together with a hallucination. Do you have a suggestion to declare functions higher up while preserving the style? See a motivation further down. Example 1 \documentclass[border=3pt,tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \tikzset{define functions/.style={% declare function={ A = 1.0; a = 0.5; f(\x) = A*\x^a; }, }, } \begin{document} \begin{tikzpicture} \begin{axis}[ domain=0:100, samples=100, ] \addplot[define functions] {f(x)}; \end{axis} \end{tikzpicture} \end{document} Example 2 \documentclass[border=3pt,tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \tikzset{define functions/.style={% declare function={ A = 1.0; a = 0.5; f(\x) = A*\x^a; }, }, } \pgfplotsset{ every axis plot/.append style={define functions}, } \begin{document} \begin{tikzpicture} \begin{axis}[ domain=0:100, samples=100, ] % [define functions] not used here \addplot {f(x)}; \end{axis} \end{tikzpicture} \end{document} LLM talking now: Example 1 \addplot[define functions] {f(x)}; You explicitly attach the define functions style only to that plot. No other styles are affected. PGFPlots uses the default plot style, which is a thin black line (black, line width 0.4pt). Example 2 \pgfplotsset{every axis plot/.append style={define functions}} \addplot {f(x)}; You append the define functions style to every plot. But here’s the subtlety: every axis plot applies before the default plot style is applied, and declare function is a key that is not strictly separate from plotting keys. What happens internally: PGFPlots interprets your appended style as including both the function declaration and the style from the first plot in your style list. Because of key expansion order, the default line style is overridden. The plot falls back to the first "unknown" style PGFPlots sees for drawing, which is often the blue mark=* style (used for points), producing thick blue dots. Why this happens every axis plot is applied before \addplot options are merged. declare function is technically a "style key" in the PGFPlots system. PGFPlots sees a style (from every axis plot) that contains no explicit draw key, so it falls back to its default marker style (mark=*, thick, blue). When you attach [define functions] directly to \addplot, the default line style is preserved, so you get a thin black line. How to fix it You need to combine your define functions style with the standard line style: if you want to keep PGFPlots defaults but still append: \pgfplotsset{ every axis plot/.append style={define functions, /pgfplots/line} } Me speaking again: No this doesn't work and nor do the several other suggestions I received. Motivation: I would save different parameter values in distinct files and load them with, say \input{func1.tex}, so I can share code across multiple figures. The syntax used in declare function is natural, unlike an alternative like \pgfmathdeclarefunction{f}{1}{\pgfmathparse{1.0*#1^(0.5)}}. I'm not averse to trying something radically different from my current approach, including using LuaTeX or Python.
- Arrows along path are misaligned after unrelated calculationsby PatrickT on October 27, 2025 at 7:08 am
The objective is to draw arrows that show convergence to a particular coordinate. The code below has served me well in simple cases. But attempting to use coordinates calculated with the intersections library caused a vertical misalignment. In the MWE the derived coordinates are not even used: the misalignment seems to be caused by the calculations. I would appreciate help fixing the issue. Any other advice to optimize the code is welcome. \documentclass[border=3pt,tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{calc} \usetikzlibrary{intersections} % set up all axes \pgfplotsset{% every axis/.append style={% axis styles xmin = 0, xmax = 250, ymin = 0, ymax = 60, ticks = none,% remove all ticks grid = none,% remove all grids clip = false,% remove clip },% }% % Define coordinates \newcommand{\SetCoordinates}{% % coordinates \coordinate (A) at (0,30); \coordinate (B) at (100,0); % calculations below interfere somehow... % define first path \addplot [draw=none, forget plot, domain=-1:200, restrict y to domain=-1:100, name path global=first path] {sqrt(x)}; % define second path \addplot [draw=none, forget plot, domain=-1:200, restrict y to domain=-1:100, name path global=second path] {0.10*x}; % find the intersection of first path and second path \path [name intersections={of=first path and second path, by={E}}]; }% % define styles for arrows along path \usetikzlibrary{arrows} \usetikzlibrary{decorations.markings} % see: https://tikz.dev/library-decorations#sec-50.2 \usetikzlibrary{fpu}% use with [/pgf/fpu/install only={reciprocal}] \tikzset{ set arrows onpath/.code={\pgfqkeys{/tikz/arrows onpath}{#1}}, set arrows onpath={end/.initial=>, opt/.initial=}, /pgf/decoration/Mark/.style={ mark/.expanded=at position #1 with { \noexpand\arrow[\pgfkeysvalueof{/tikz/arrows onpath/opt}]{\pgfkeysvalueof{/tikz/arrows onpath/end}} } }, arrows onpath/.style 2 args={ set arrows onpath={#1}, postaction={ decorate,decoration={ markings, Mark/.list={#2}, },% },% },% }% % Arrow | x-axis | Convergence \NewDocumentCommand{\hArrows}{ m O{ 30pt } }{% \path [draw=none, arrows onpath={end=latex, opt={black,scale=0.9}}{0.50,0.75,1.00}] ($(#1)+(+#2,0)$) -- (#1); \path [draw=none, arrows onpath={end=latex, opt={black,scale=0.9}}{0.50,0.75,1.00}] ($(#1)+(-#2,0)$) -- (#1); }% % Arrow | y-axis | Convergence \NewDocumentCommand{\vArrows}{ m O{ 30pt } }{% \path [draw=none, arrows onpath={end=latex, opt={black,scale=0.9}}{0.50,0.75,1.00}] ($(#1)+(0,+#2)$) -- (#1); \path [draw=none, arrows onpath={end=latex, opt={black,scale=0.9}}{0.50,0.75,1.00}] ($(#1)+(0,-#2)$) -- (#1); }% \begin{document} \begin{tikzpicture} \begin{axis} \SetCoordinates \hArrows{B}[50pt] \vArrows{A}[10pt]% buggy \node [left, align=center, anchor=south west] at (40,20) {The vertical alignment\\ is thrown off\\ by the calculations inside\\ command \texttt{SetCoordinates}.\\ Why?}; \end{axis} \end{tikzpicture} \end{document}
- PGFPlots Line Patch Plot with Decorationby trumpeter201 on October 21, 2025 at 9:08 pm
Using tikz and PGFPlots, I am creating a patch plot from data table with the line patch type. I would like to decorate the end of each line with an arrow. What is the best way to do this? Below is a minimal example, missing the arrow decorations. Note that I need to use the table syntax to generate the plot, as the real data is stored in a large text file. \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{patchplots} \begin{document} \begin{tikzpicture}[] \begin{axis}[] \addplot[patch, patch type = line] table { x y 0 0 0 1 0 0 1 1 0 0 1 0 }; \end{axis} \end{tikzpicture} \end{document} This code generates the following plot:
- `tikzviolinplots` produces `! Dimension too large.`by Rubem Pacelli on October 19, 2025 at 7:26 pm
%%% featues %%% % violinplot % CAVEAT: run it as `latexmk -pdf -shell-escape -interaction=nonstopmode -g main.tex` %%% picture %%% % https://tex.stackexchange.com/a/679168/222785 \documentclass{article} \usepackage{pgfplots} \usepackage{tikzviolinplots} \usepackage{minted} \usepackage{scontents} % Ensure pgfplots uses a modern compat level \pgfplotsset{compat=newest} \usepgfplotslibrary{external} \usemintedstyle{gruvbox-light} \tikzexternalize \begin{scontents}[write-out=violinandboxplotexample.dat] trn,val 19.334,69.122 2.146,3.136 1.629,2.080 2.930,1.629 9.208,1.332 6.265,2.189 74.253,1.392 2.097,3.970 1.328,1.624 1.814,19.254 2.090,6.546 1.814,8.212 3.177,3.484 2.239,2.601 1.213,1.565 2.697,9.208 1.550,4.145 19.254,2.770 5.409,2.318 1.679,2.357 1.392,67.159 2.697,3.047 4.592,2.021 1.671,1.583 6.265,1.294 13.373,2.127 3.216,1.353 3.143,3.858 3.779,1.578 74.253,18.707 3.779,6.360 1.580,7.979 1.642,3.385 1.580,2.527 2.189,1.520 1.665,8.946 1.696,4.027 2.041,2.692 2.770,2.252 4.145,2.290 2.207,60.506 1.671,2.745 3.216,1.821 7.512,1.426 3.970,1.166 1.624,1.916 1.307,1.219 2.163,3.475 3.136,1.422 1.665,16.854 4.465,5.730 9.766,7.189 4.465,3.049 1.703,2.277 1.702,1.370 1.550,8.060 2.892,3.628 4.592,2.425 1.213,2.029 5.409,2.063 3.830,68.544 3.840,3.110 19.334,2.063 8.212,1.615 1.362,1.321 1.220,2.171 1.362,1.381 1.220,3.937 3.484,1.611 2.239,19.093 5.560,6.491 1.642,8.144 2.357,3.454 9.766,2.579 2.163,1.552 5.560,9.131 1.703,4.111 2.041,2.747 2.138,2.298 3.830,2.338 %10.174,70.018 % UNCOMMENT TO SEE THE CHAOS \end{scontents} \tikzexternaldisable \begin{document} \begin{tikzpicture} \violinsetoptions[ % averages, data points, scaled, ]{ xmin=0,xmax=5, ymin=0,ymax=100, xlabel style={ yshift = {-2*height("a")} }, ymajorgrids=true, ylabel={Same property}, } \violinplotwholefile[% primary color=red, secondary color=blue, indexes={trn,val}, spacing=1.0, labels={% $\alpha$, $\beta$, $\gamma$, $\delta$, }, col sep=comma, dataset size=1pt, dataset mark=*, dataset fill=black!50!white, dataset fill opacity=1.0, average mark=x, average size=5pt, ]{violinandboxplotexample.dat} \end{tikzpicture} \end{document} Uncommenting that line in this MWE leads to: ! Dimension too large. <recently read> \pgfmath@x l.141 ]{violinandboxplotexample.dat} How to fix that?
- Loop over pgfplotstable rows and axis, or any other methodby username on October 14, 2025 at 1:14 pm
I would like to create a graphic that does what this file is doing,but without going through each individual line \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{loglogaxis}[ xlabel=Energy, ylabel=GDP, title={Data: Energy vs GDP}, grid=both, xmin=1000, xmax=100000, ymin=1000000, ymax=1000000000, xtick={1000, 10000, 100000}, ytick={1000000, 10000000, 100000000, 1000000000}, xticklabels={$10^3$, $10^4$, $10^5$}, yticklabels={$10^6$, $10^7$, $10^8$, $10^9$} ] % Add circles \filldraw[blue, opacity=0.3] (axis cs:1981.7102,40578847) circle (6.37015282391247*1pt); \filldraw[blue, opacity=0.3] (axis cs:17111.953,2827614) circle (1.68155106969726*1pt); \filldraw[blue, opacity=0.3] (axis cs:14782.2,45477391) circle (6.74369268279627*1pt); \filldraw[blue, opacity=0.3] (axis cs:7397.4863,35635028) circle (5.96950818744727*1pt); \filldraw[blue, opacity=0.3] (axis cs:7888.164,169384891) circle (13.0147950809838*1pt); \filldraw[blue, opacity=0.3] (axis cs:38214.496,145579889) circle (12.0656491329725*1pt); \filldraw[blue, opacity=0.3] (axis cs:72679.26,341534041) circle (18.4806396263766*1pt); % Add labels \node[] at (axis cs:1981.7102,40578847) {}; \node[] at (axis cs:17111.953,2827614) {}; \node[] at (axis cs:14782.2,45477391) {}; \node[] at (axis cs:7397.4863,35635028) {}; \node[] at (axis cs:7888.164,169384891) {Bangladesh}; \node[] at (axis cs:38214.496,145579889) {Russia}; \node[] at (axis cs:72679.26,341534041) {United States}; \end{loglogaxis} \end{tikzpicture} \end{document} I have tried using a \foreach loop, something like \pgfplotstableread[col sep = comma]{ x,y,r,l 1981.7102,40578847,6.37015282391247, 17111.953,2827614,1.68155106969726, 14782.2,45477391,6.74369268279627, 7397.4863,35635028,5.96950818744727, 7888.164,169384891,13.0147950809838,Bangladesh 38214.496,145579889,12.0656491329725,Russia 72679.26,341534041,18.4806396263766,United States }\mytable and within the plot \foreach \row in {0,...,4} { \pgfplotstablegetelem{\row}{x}\of\mytable \let\x=\pgfplotsretval \pgfplotstablegetelem{\row}{y}\of\mytable \let\y=\pgfplotsretval \pgfplotstablegetelem{\row}{r}\of\mytable \let\r=\pgfplotsretval \pgfplotstablegetelem{\row}{l}\of\mytable \let\t=\pgfplotsretval \draw[blue, opacity=0.3] at ({\x}, {\y}) circle (\r*5pt); \node[font=\tiny] at (\x, \y) {\t}; but that fails when i do it within the axis framework.
- Pgfplots -- Make units exactly 1 cmby klirk on October 13, 2025 at 1:56 pm
I am trying to make a pgf plot so that when printed, the units are exactly 1 cm, i.e, the grid lines should be 1 cm apart. However, whatever I do, I cannot make it work and I really don't know why. This is my minimal example: \documentclass[a4paper]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ width=6cm, height=6cm, scale only axis, enlargelimits=false, xmin=0, xmax=6, ymin=0, ymax=6, grid=both, xtick={0,1,...,6}, ytick={0,1,...,6}, ] \end{axis} \end{tikzpicture} \end{document} When I print the pdf and measure distances with a ruler, the grid lines have distance slightly smaller than 1cm, resulting in a size of around 5.7 cm instead of 6 cm for the entire axis.
- Undesirable slant in ylabel in pgfplotsby Scholar on October 11, 2025 at 3:20 am
I am trying to plot multiple curves, of which some are trigonometric, on the same plot. However, the ylabel appears to be slanted every time I use trig format=rad in my code. If I remove this, everything works fine and the label appears the way I expect it to (standard ylabel). Here is the MWE. Any help leading to a fix is highly appreciated. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{geometry} \begin{document} \begin{tikzpicture} \begin{axis}[ trig format=rad, ylabel={This is a test label}, xlabel={$t$ (s)}, grid=both, axis lines=box, xmin=0, xmax=20, ] \addplot [blue, thick, domain=0:20, samples=100] {2*(1-cos(x))}; \end{axis} \end{tikzpicture}
- How do I prevent "see-through" when overlaying a surf plot with a point cloud?by Peter1509 on October 10, 2025 at 3:08 pm
I am trying to create a surf plot with an additional point cloud on top. The data for both is saved in two different tables, which are then read and plottet into the same axis environment. Currently I have the problem, that some points (which are actually covered by the surf plot) can be seen through the surface. I want only be able to see the points, which from the given view perspective are not covered by some part of the surface plot. I already tried the pgfplot option \pgfplotsset{set layers}, but it didn't change anything. Also the order of \addplot3 -commands had no influence on the resulting plot. Are there any other options to solve my problem? Here is the important part of my current code structure: \pgfplotsset{set layers} \begin{tikzpicture} \begin{axis}[% width=0.65\figurewidth, height=1.2\figureheight, at={(0\figurewidth,0\figureheight)}, scale only axis, xmin=0, xmax=20, xtick distance = 5, tick align=outside, xlabel style={font=\color{white!15!black}}, xlabel={$t$ in \si{\hour}}, ymin=0, ymax=0.605, ylabel style={font=\color{white!15!black}}, ylabel={$z$}, zmin=0, zmax=220, ztick distance = 50, zlabel style={font=\color{white!15!black}}, zlabel={$x(z,t)$}, view={-35}{60}, axis background/.style={fill=white}, title style={font=\bfseries}, axis x line*=bottom, axis y line*=left, axis z line*=left, xmajorgrids, ymajorgrids, zmajorgrids, ylabel near ticks, xlabel near ticks, title style={font=\small}, xlabel style={font=\footnotesize, yshift = 2mm}, ylabel style={font=\footnotesize, yshift = 1mm,xshift = 5mm}, xticklabel style ={/pgf/number format/fixed, /pgf/number format/precision=3}, ylabel style={font=\footnotesize, rotate=-90}, yticklabel style ={/pgf/number format/fixed, /pgf/number format/precision=3,/pgf/number format/use comma}, zticklabel style = {yshift = -2.5mm}, zlabel shift={-5pt}, zlabel style = {xshift = -3mm}, legend style={font=\scriptsize}, ticklabel style={font=\scriptsize} ] \addplot3 [only marks, mark=*, mark options={}, mark size=1.0607pt, color=red, fill=red, forget plot, z buffer=sort] table[meta index = 2, col sep=tab, x expr=\thisrowno{0}/3600, y index=1] {tikz/Simulationsplots/xzt_chebypoints-2.tsv}; \addplot3[% surf, shader=flat corner, colormap={mymap}, mesh/rows=30, z buffer=sort] table[col sep=tab, x expr=\thisrowno{0}/3600, y index=1] {% tikz/Simulationsplots/xzt_chebypoints-1.tsv}; \end{axis} \end{tikzpicture}%
- How to add extra y ticks to a pgfplots axis on the right with fixed width?by Tristan Nemoz on October 10, 2025 at 8:39 am
I have the plot of several functions on a single axis, and I would like to add extra y ticks on the right of the plot to show the different numbers to which these functions converge to. However, I can't manage to have the total tikzpicture to be \textwidth wide, the extra ticks label making an overfull hbox. MWE: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel=$x$, ylabel={$f(x) = x$}, width=\textwidth, height=\axisdefaultheight, extra y ticks={1}, extra y tick labels={\(\log_2(5)-\sum_ii\)}, extra y tick style={ yticklabel pos=right, grid=major, major grid style={gray, thin, densely dashed}, }, ] \addplot {x}; \end{axis} \end{tikzpicture} \end{document} I've tried the solution of this answer to no avail, it still results in an overfull hbox: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel=$x$, ylabel={$f(x) = x$}, width=\textwidth, height=\axisdefaultheight, extra y ticks={1}, extra y tick labels={\makebox[0pt][l]{\(\log_2(5)-\sum_ii\)}}, extra y tick style={ yticklabel pos=right, grid=major, major grid style={gray, thin, densely dashed}, yticklabel style={ % add a name to the extra y tick label name=ylabel-\ticknum, }, }, ] \addplot {x}; \end{axis} \pgfmathsetlengthmacro{\MyExtraLabel}{width("$\log_2(5)-\sum_ii$")} \path (ylabel-0) -- +(\MyExtraLabel,0); \end{tikzpicture} \end{document} Finally, I also tried using a second axis environment, as in this answer, once again to no avail: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel=$x$, ylabel={$f(x) = x$}, width=\textwidth, height=\axisdefaultheight, ] \addplot {x}; \end{axis} \begin{axis}[ width=\textwidth, height=\axisdefaultheight, hide x axis, axis y line*=right, ymin=-6, ymax=6, ytick=\empty, extra y ticks={1}, extra y tick labels={\(\log_2(5)-\sum_ii\)} ] \addplot[draw=none] {x}; % dummy plot \end{axis} \end{tikzpicture} \end{document} Also, this solution would force me to know the ymin and ymax of the first plot if I'm not mistaken, which isn't convenient. Is there a way to make these extra ticks on the right taken into account when computing the width of the end figure?
- Adding a colormap to a solution curve of a vector fieldby Black Mild on October 7, 2025 at 8:29 pm
Here the curve is drawn with a single color (red) It's easy to get the solution curve. The below figure is drawn in this app for y'=x^2+y^2-1, y(0)=1/2. As you can notice the color of the curve is varying from red (x<-1) to purple (-1<x<1) then to blue (x>1). It is not color set of the rainbow, so it is not synchronious to the Rainbow colormap. My question: How to add a given colormap (such as Rainbow) to a solution curve of a vector field? I guess this is a kind of popular, but can not find a way with Asymptote. I expect not only Asymptote code but also any others as TikZ, MetaPost, lua, etc. The code should be apply for any colormaps Please use my code here as MWE.
- Plotting functions without sampling artefactsby arctiq on September 24, 2025 at 3:28 pm
I am interested in a generic technique to visualize functions in a quality appropriate for journal articles. Consider the function $$-\sqrt{\lvert x-\tan y \rvert}$$ over $[0,1]^2$. Tools like WolframAlpha can plot it beautifully with Plot3D[-Sqrt[Abs[x - Tan[y]]], {x, 0, 1}, {y, 0, 1}]: However, PGFplots produces unacceptable artefacts: \documentclass[border=10pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[view={30}{30}, domain=0:1] % Unacceptable plot of the desired function \addplot3[surf,shader=faceted interp]{-sqrt(abs(x-tan(deg(y))))}; % Desired shape of the ridge \addplot3[domain=0:pi/4, samples y=0] ({tan(deg(x))},{x},{0}); \end{axis} \end{tikzpicture} \end{document} Increasing the number of samples does not help as the slope approaches infinity near the $x=\tan y$ singularity. Postprocessing will not help as the sampling loses information. The black curve indicates the correct shape and position of the ridge compared to the actual result. I run into this all the time and know of no solution except drawing it by hand. Solutions involving external tools and LuaLaTeX are acceptable. GNUplot can not handle this either. I was unable to find a solution in the PGFplots documentation. AI tools provide no help either.
- Bug in pgfplots? "xticklabels" considers order in csv while "symbolic x coords" does notby nopx on May 19, 2025 at 11:47 am
For barplots: I found that xticklabels does considers the order in the csv files while symbolic x coords` does not. This leads to situations where incorrect data is displayed. That is the ticks do not appear for the correct data. In the below example it shows the value two for metric C, even though the value in the csv is three. What am I doing wrong? How to fix this? Here is a minimal example: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \iftrue % If true, the displayed data is wrong! The alternative is just two rows flipped, see below. \begin{filecontents*}{data.csv} ,methodA,methodB,methodC metricA,1,1,1 metricC,3,3,3 metricB,2,2,2 \end{filecontents*} \else \begin{filecontents*}{data.csv} ,methodA,methodB,methodC metricA,1,1,1 metricB,2,2,2 metricC,3,3,3 \end{filecontents*} \fi \begin{document} \pgfplotstableread[col sep = comma]{data.csv}\table \begin{tikzpicture} \begin{axis}[ ybar, symbolic x coords={metricA,metricB,metricC}, xticklabels={A,B,C}, xtick=data, ] \addplot [fill=red ] table [x index=0, y=methodA] {\table}; \addplot [fill=blue ] table [x index=0, y=methodB] {\table}; \addplot [fill=green] table [x index=0, y=methodC] {\table}; \end{axis} \end{tikzpicture} \end{document} If we extend the example to 6 different rows, it become even more confusing. \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{filecontents*}{data.csv} ,methodA,methodB,methodC A,1,1,1 B,2,2,2 D,4,4,4 E,5,5,5 F,6,6,6 C,3,3,3 \end{filecontents*} \begin{document} \pgfplotstableread[col sep = comma]{data.csv}\table \begin{tikzpicture} \begin{axis}[ ybar, symbolic x coords={A,B,C,D,E,F}, xtick=data, xticklabels={A,B,C,D,E,F}, ] \addplot [fill=red ] table [x index=0, y=methodA] {\table}; \addplot [fill=blue ] table [x index=0, y=methodB] {\table}; \addplot [fill=green] table [x index=0, y=methodC] {\table}; \end{axis} \end{tikzpicture} \end{document} The xticklabels seems to be completely confused about the labels. I don't see any pattern anymore ... Please, does anyone understand this?
- pgfplots - clipping on different layersby mm96 on January 3, 2025 at 12:47 pm
I don't understand how clipping on different layers works. In the example, I tried to clip the grid and the function +x, but it seems the clipping always takes place on the main layer: \documentclass{scrartcl} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \pgfplotsset{set layers=standard} \begin{axis}[ xmin=-3, xmax=3, ymin=-3, ymax=3, axis lines = center, enlargelimits={abs=0.4cm}, grid=both, grid style = { on layer = axis grid, }, ] \addplot[on layer = axis grid] {x}; \addplot [on layer = main] {-x}; \clip [on layer = axis grid](-3,-3) rectangle (3,3); \end{axis} \end{tikzpicture} \end{document} I got the idea from percusses answer from this question (don't enlarge grid) but couldn't bring it to work even when trying "execute at begin" in different combinations. Thanks for your advice!
- Questions about pgfplot (ticks position, position of axis label, aspect ratio, etc)by Dimitris on September 26, 2024 at 3:11 pm
I used the following code to plot a sequence: \begin{tikzpicture} \begin{axis}[ title={Graphique de la suite \(u_n = 3n^2 - 5\)}, %samples=60, domain=0:5, xmax=5.5, xmin = -0.25, restrict y to domain=-20:80, ymax=80, ymin=-20, axis lines=left, % y=0.5cm/15, % x=0.5cm, grid=both, axis lines=middle, % Pour avoir des axes au milieu xtick={0,...,5}, compat=newest, ytick={-15,0,15,...,75}, x tick label style={below right}, y tick label style={above left}, compat=newest, xlabel=$n$, xlabel style={at={(1,0.15)}, anchor=north, above right}, ylabel=$u_n$, ylabel style={rotate=-90,at={(0.05,1)}, anchor=south} ] % Courbe de la suite \addplot[color=blue, thick] coordinates { (0,-5)(1,-2)(2,7)(3,22)(4,43)(5,70) }; % Points marqués en rouge \addplot[only marks, mark=*, mark options={scale=0.75, color=red}] coordinates { (0,-5)(1,-2)(2,7)(3,22)(4,43)(5,70) }; \end{axis} \end{tikzpicture} I get the following plot. I have a few questions regarding the customization of axis labels and ticks in a TikZ/pgfplots environment: Centering Axis Labels: I want the axis labels to be exactly centered on their respective axes. Currently, I'm doing this manually through trial and error, but I assume there’s a more straightforward setting to achieve this automatically. Is there a simple way to center them properly? Tick Placement: How can I adjust the ticks so that they appear closer to their respective axes? I’d like the ticks to be positioned along the axis lines. Displaying Zero Ticks: I’m trying to make sure the tick at zero is visible, but currently, it doesn’t show up. How can I ensure that the ticks at zero are displayed on both axes? Square Axes: How can I force both axes to have the same scale, so that the units on the 𝑥-axis and 𝑦-axis are equal, resulting in a square plot? Thanks a lot for your help!
- 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
- How can I make a violin plot in PGFPlotsby hpekristiansen on October 25, 2022 at 2:05 pm
Taking the data from this question: Spread the dots in boxplot in pgfplots How can I make a violin plot.
- 3d intersectionsby Blooment on November 7, 2020 at 7:47 pm
As exercise, I'm trying to draw the intersection of the prism [0,2] x [0,4] x [0,6], and the plane x + y + z = 5. My result is: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture}[x={(-0.45cm,-0.385cm)},y={(1cm,-0.1cm)},z={(0,1cm)}] \draw [->] (0,0,0) -- (6,0,0) node [below left] {$x$}; \draw [->] (0,0,0) -- (0,6,0) node [right] {$y$}; \draw [->] (0,0,0) -- (0,0,6) node [right] {$z$}; \filldraw [thick, orange, fill opacity=0.3] (0,0,5) -- (0,4,1) -- (1,4,0) -- (2,3,0) -- (2,0,3) -- cycle; \filldraw [thick, blue, fill opacity=0.2] (2,3,0) -- (2,0,3) -- (5,0,0) -- cycle; \filldraw [thick, blue, fill opacity=0.2] (1,4,0) -- (0,5,0) -- (0,4,1) -- cycle; \filldraw [thick, orange, fill opacity=0.3] (2,3,0) -- (2,0,0) -- (2,0,3) -- cycle; \filldraw [thick, orange, fill opacity=0.3] (1,4,0) -- (0,4,0) -- (0,4,1) --cycle; \end{tikzpicture} \end{document} I have some questions now: I think there's a lot of code just to represent an easy mathematical volume as [0,2] x [0,4] x [0,6]. Is there some more efficient way of drawing it? Do I need to calculate the intersections by hand and then represent it? Or is there any direct method? How can I obtain the same result by using an axis environment and \addplot commands instead of \draw? I've tried but I'm new to \addplot3 and I'm having trouble with axis position (view={}{}), colormap has not a homogeneus color, the surface has a grid that difficults the understanding of the picture and I have the same doubt on intersections, Do I need to calculate them by hand? Full prism is: \draw [fill=orange, fill opacity=0.3] (0,0,6) -- (2,0,6) -- (2,4,6) -- (0,4,6) -- cycle ; \draw [fill=orange, fill opacity=0.3] (2,0,0) -- (2,0,6) -- (2,4,6) -- (2,4,0) -- cycle ; \draw [fill=orange, fill opacity=0.3] (2,4,0) -- (0,4,0) -- (0,4,6) -- (2,4,6) -- cycle ;
- Plotting function ℝ² →ℝ with pole at (0,0) smoothlyby Wizard of Math on May 30, 2020 at 1:56 pm
I would like to plot the function f: ℝ² →ℝ, definited by f(x,y)=(xy)/(x^2+y^2). But the following problem comes up: At (0,0) the function is not continous and therefore it looks kind of jagged. To solve this problem i could force the function to input specific points but i can't find it anywhere an don't know if that is even possible. Code: \begin{tikzpicture}[] \begin{axis}[axis lines=center, axis on top, xtick=\empty, ytick=\empty, ztick=\empty, xrange=-2:2, yrange=-2:2 ] % function \addplot3[domain=-2:2,y domain=-2:2,colormap/viridis,surf,opacity=0.5,samples = 55] {(x*y)/(x^2+y^2)}; \end{axis} \end{tikzpicture} How do i make this function look smooth? Any help would be greatly appreciated 🙂 (Just increasing the Samples doesnt do that much, and I run into the following error: TeX capacity exceeded, sorry [main memory size=3000000])
- Documentation of additional keys or commands when using TikZ or pgfplots in beamer presentationsby Diaa on September 25, 2019 at 12:51 pm
After going through this answer, I wondered if there is a documentation of the available keys that can be used as options when drawing using TikZ or pgfplots. For example, the key alt in \node[alt={<2>{... I didn't find it documented in either manual of TikZ or beamer. So, where can I find good documentation of all the additional available keys that can be used when drawing using TikZ or pgfplots?
- Custom numbering of figuresby Gennaro Arguzzi on December 19, 2017 at 8:53 pm
I'd like to number figures in a custom way. For example: fig. 1, fig. 2a, fig. 2b, fig. 3 (among figures there is text). \documentclass[10pt,a4paper]{report} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{pgfplots} \begin{document} Bla bla bla \begin{figure}[h] \centering \begin{center} \begin{tikzpicture} \draw (0,0) circle (1cm); \end{tikzpicture} \end{center} \caption{Es.} \end{figure} Bla bla bla \begin{figure}[h] \centering \begin{center} \begin{tikzpicture} \draw (0,0) circle (1cm); \end{tikzpicture} \end{center} \caption{Es.} \end{figure} bla bla \begin{figure}[h] \centering \begin{center} \begin{tikzpicture} \draw (0,0) circle (1cm); \end{tikzpicture} \end{center} \caption{Es.} \end{figure} bla \begin{figure}[h] \centering \begin{center} \begin{tikzpicture} \draw (0,0) circle (1cm); \end{tikzpicture} \end{center} \caption{Es.} \end{figure} \end{document} Thank you so much for your time.
- Change color of \addplot in a \foreach loop (pgfplots)by Benjamin1956 on February 14, 2017 at 11:38 am
I have this pgfplots plot and I want every single graph to have a different color. A gradient from red to blue or something else (m=2 should be red, m=11 should be blue and all the other m should be between this). I need this to work even when I change the amount of graphs. I already tried to transfer the code lines from this example, but I can't get it working: Plotting a graph with several values of a parameter The minimum working example is added below. Thank you. \documentclass[12pt]{article} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage{pgfplots} \pgfplotsset{compat=newest} \pgfplotsset{ gainplot/.style={ axis x line*=box, xmax=10, xmin=0.1, xmode=log, width=14cm, xlabel=$F_\textup{x}$, xticklabel style={yshift=-0.2cm,}, xtick={0.1,1.0,10.0}, xticklabels={{$0.1$},{$1.0$},{$10.0$}}, axis y line*=box, ymax=3, ymin=0, ymode=normal, height=7cm, ylabel=$K$, yticklabel style={xshift=-0.2cm,}, ytick={0,1,2,3 }, yticklabels={{$0$},{$1$},{$2$},{$3$}}, grid = both, grid style={line width=0.2pt,}, legend style={ font=\scriptsize, at={(0.5,1.03)}, anchor=south, draw=none, }, legend columns=5, }, gainplot/.belongs to family=/pgfplots/scale, } \pgfmathdeclarefunction{gaincurve}{2}{% \pgfmathparse{% (x^2*(#2-1)/(sqrt((#2*x^2-1)^2+x^2*(x^2-1)^2*(#2-1)^2*#1^2))) }% } \tikzstyle{gaincurvestyle}=[ smooth, %thick, mark=none, domain=0.1:10, samples=100, ] \begin{document} \begin{figure}[] \centering \begin{tikzpicture} \begin{axis}[gainplot] \foreach \m in {2,3,...,11}{ \addplot[gaincurvestyle,red]{gaincurve(0.2,\m)}; %%% Here help is needed. \addlegendentryexpanded{$m=\m$} } \end{axis} \end{tikzpicture} \caption{Placeholder.} \end{figure} \end{document}
- Differential Equation direction plot with pgfplotsby Alexander Mathiasen on October 16, 2013 at 11:05 am
In earlier thread Jake provided some code whom successfully draws the following differential equations in the range [0; 1] dy/dx=2*x dy/dx=x*sqrt(x) See: How to draw slope fields with all the possible solution curves in latex I have not been able to determine how to change the range to [-1; 1] for both dimensions. My attempt xmin=-1.1, xmax=1.1, % Axis limits ymin=-1.1, ymax=1.1, domain=-1:1, y domain=-1:1, Also, I had some trouble with the notation for a differential equation that consists of y, example (dy/dx=x^2+y^2-1). My attempt: declare function={f(\x) = \x^2 + f(\x)^2 - 1;}