pgfplots
- Controlling what appears in front in a 3d pgfplotby James on July 12, 2026 at 6:00 pm
I'm trying to make a nice diagram to illustrate partial derivatives for my multivariable class. I have the graph of a function, a plane, the intersection of these in the graph, a tangent line, and some guide lines to show what's occurring, but (presumably because of the order in which they appear in the code) the diagram doesn't respect what object is behind a different object, i.e., the graph is drawn on top of the plane, or the plane is drawn on top of the graph, even though they ``should'' pass through one another. Is there any nice way to make whatever ``should'' be on top be drawn on top without manually finding intersections and having different domains/clip regions for different features? My code so far is below, along with the image that is produced \begin{standalone} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[axis lines = center, xmin = 0, xmax = 3, ymin = 0, ymax = 3, view = {100}{30}, xlabel = {$x$}, ylabel = {$y$}, zlabel = {$z$}, xtick=\empty, ytick=\empty, ztick=\empty, ] % Using f(x,y) = 2 - (x-2)^3 - (y-1.5)^2 %graph \addplot3[ domain =1:3, y domain = 0.5:2.5,surf,colormap/viridis, opacity=0.9] {-(x-2)^3 - (y-1.5)^2 + 2}; %plane \draw[fill = blue!90, color = blue, opacity = 0.3] (2,0,0)--(2,3,0)-- (2,3,3) node[black, above, opacity = 0.9] {$x=a$}--(2,0,3)--cycle ; %intersection of line and plane \addplot3[domain = 0.5:2.5, blue, samples y = 1, thick] ({2},{x},{2 - (2-2)^3 - (x-1.5)^2}); %tangent line \addplot3[black, thick, domain = -1:1.23] ({2},{x+1},{-2*(1-1.5)*x + 2 - (1-1.5)^2}); %point of tangancy \draw[fill = black] (2,1, {2 - (1-1.5)^2}) circle (2pt); %guide lines for point \draw[dashed, thick] (2,0,0)--(2,1,0) node[below] {$(a,b,0)$}--(0,1,0); \draw[dashed, thick,] (2,1,0) -- (2,1,{2 - (1-1.5)^2}); \end{axis} \end{tikzpicture} \end{document}
- how to align axis-coordinate system with tikzpicture-coordinate systemby flawr on June 30, 2026 at 3:13 pm
I'd like to use a pgfplots axis environment to render some plots. I'd like them to be aligned with the surrounding TiKz graphics. However, I have not yet managed to find the correct options. I'm also only interested in the plotted line itself, so no ticks or axes need to be drawn in addition. So far I have this (failed) example. My goal would be aligning the coordinate system the axis environment such that the two curves are right on top of each other. With the width/height I assumed I could set the exact dimensions, but that already seems to be off. Is there a way to modify this axis-environment to match the coordinate system of the tikzpicture-environment? \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \draw[lightgray] (-2, -3) grid (4, 4); \fill[lightgray] (0,0) circle (0.2); % origin \draw[green] plot [red, domain=-2:4, samples=200] (\x, {exp(-abs(\x)^2)}); \begin{axis}[ xtick=\empty, ytick=\empty, hide axis, xmin=-2, xmax=4, axis equal, width=6cm, height=7cm, anchor=south west, at={(-2cm,-2cm)}, ] \addplot [red, domain=-2:5, samples=200] (\x, {exp(-abs(\x)^2)}); \end{axis} \end{tikzpicture} \end{document}
- `memoize` and `PGFPlots`: multiple graphs get "merged" into one?by Thibault de Villèle on June 29, 2026 at 12:08 pm
I've got a bunch of figures which are PGFPlots elements side by side, as such: \begin{figure}[ht]% \centering% \begin{subfigure}{.49\textwidth}% \centering% \sizedplot{../path/to/plot-dir/bunny-multires}{p1-rmse.tikz}% \end{subfigure}\hfill% \begin{subfigure}{.49\textwidth}% \centering% \sizedplot{../path/to/plot-dir/bunny-multires}{p1-times-graph.tikz}% \end{subfigure}\\[1pt]% % Note: the `bunny-multires-plot` key is defined as the "legend name" in p1-rmse.tikz: \pgfplotslegendfromname{bunny-multires-plot}% \caption{Blah, blah, blah.}% \label{fig/bunny-multires}% \end{figure}% Where the \sizedplot command is defined as such: \NewDocumentCommand{\sizedplot}{s O{\textwidth} m m}{% \bgroup% \def\basepath{#3}% \def\fullpath{\basepath/#4}% \mmznext{meaning to salt={\fullpath}}% \begin{memoize}% \IfBooleanTF{#1}% If star, do not resize to #2. {\begin{tikzpicture}\input{\fullpath}\end{tikzpicture}}% {\resizebox{#2}{!}{\begin{tikzpicture}\input{\fullpath}\end{tikzpicture}}}% \end{memoize}% \egroup% }% This indirection is mainly due to the fact I include data from CSV files relative to the path of the plots, like: \addplot table [options] {\basepath/losses.csv}. When doing this, and enabling external compilation through the use of the memoize package, both graphs (the subfigure elements) are detected as the same "source", leading to one of the graphs (often the second one in the order they were defined) being copied in both sub-figures after memoization + recompilation. What could go wrong here? I've added -- as shown above -- the full path as a source for the salt in memoize's options, hoping they would thus get detected as two different graphs, but nothing seems to make that specific use case work. If I only have one TikZ / PGFPlots image in a figure environment, it compiles just fine. Here is a MWE, with all contents laid inline (sorry, the file is a bit long as a result): \documentclass{scrarticle} \usepackage{subcaption} \usepackage{siunitx} \usepackage{tikz} \usepackage{pgfplots} % IMPORTANT: switch this on/off to see the changes. \usepackage{nomemoize} %\usepackage{memoize} \NewDocumentCommand{\ValeurLegende}{m}{\num[output-exponent-marker=e,tight-spacing=true]{#1}}% \NewDocumentCommand{\ValeurAnnotation}{m}{\bgroup\scriptsize\num[output-exponent-marker=e,tight-spacing=true]{#1}\egroup}% \mmzset{padding=0pt, include context in ccmemo, trace} \pgfplotsset{% rmse/.style={table/col sep=comma,table/x={iteration}, table/y={classic}},% timings/.style={table/col sep=comma,table/x={iteration}, table/y={time-ms}},% }% \NewDocumentCommand{\sizedplot}{s O{\textwidth} m m}{% \bgroup% \def\basepath{#3}% \def\fullpath{\basepath/#4}% \mmznext{meaning to salt={\fullpath}}% \mmznext{meaning to context={\fullpath}}% \begin{memoize}% \IfBooleanTF{#1}% If star, do not resize to #2. {\begin{tikzpicture}\input{\fullpath}\end{tikzpicture}}% {\resizebox{#2}{!}{\begin{tikzpicture}\input{\fullpath}\end{tikzpicture}}}% \end{memoize}% \egroup% }% \begin{filecontents}{inline-loss-1.csv} iteration,time-ms,loss-abs,loss-cen,loss-fro 0,217.78973,9.07334387e-02,3.75475502e-04,2.29247450e-03 1,13.39216,8.98691937e-02,3.73302639e-04,3.80451954e-03 2,11.54511,8.92234743e-02,3.69715272e-04,4.83295647e-03 3,11.24531,8.90074968e-02,3.68322566e-04,5.51446620e-03 4,11.06645,8.86987820e-02,3.66538385e-04,6.02372689e-03 5,11.16146,8.89326632e-02,3.68111941e-04,6.37550279e-03 6,11.35311,8.90174806e-02,3.68967390e-04,6.63577626e-03 \end{filecontents} \begin{filecontents}{inline-loss-7.csv} iteration,time-ms,loss-abs,loss-cen,loss-fro 0,440.79675,4.83646780e-01,8.67330883e-08,4.42878436e-03 1,120.62730,4.86005545e-01,9.31322575e-10,5.97733771e-03 2,121.23386,4.86002266e-01,9.31322575e-10,6.64955098e-03 \end{filecontents} \begin{filecontents}{inline-rmse-1.csv} iteration,classic,normalized,normalizedpercent 00000,2.43285656e-01,1.58218700e+00,158.22 00001,8.82571621e-04,2.21190803e-01,22.12 00002,8.10880039e-04,2.27497900e-01,22.75 00003,7.84764765e-04,2.19129181e-01,21.91 00004,7.73038832e-04,2.14945569e-01,21.49 00005,7.67099671e-04,2.28823943e-01,22.88 00006,7.63582473e-04,2.29091554e-01,22.91 \end{filecontents} \begin{filecontents}{inline-rmse-7.csv} iteration,classic,normalized,normalizedpercent 00000,2.43285656e-01,1.58218700e+00,158.22 00001,7.45367841e-04,1.91473720e-01,19.15 00002,6.76008989e-04,1.71335431e-01,17.13 \end{filecontents} \begin{filecontents}{inline-rmse.tikz} \begin{semilogyaxis}[% width=7cm,% height=5cm,% legend columns=7,% legend to name={plot-loss},% xtick pos=bottom,% ytick pos=left,% ylabel={\texttt{Losses}},% ]% \addplot table [rmse] {\basepath/inline-rmse-7.csv};% \addlegendentry{\(\epsilon=\ValeurLegende{1e-7}\)}% \addplot table [rmse] {\basepath/inline-rmse-1.csv};% \addlegendentry{\(\epsilon=\ValeurLegende{1e-1}\)}% \end{semilogyaxis}% \end{filecontents} \begin{filecontents}{inline-timings.tikz} \begin{semilogyaxis}[% width=7cm, height=5cm,% xtick pos=bottom, ytick pos=left,% ylabel={\(t_i~(\unit{\milli\second})\)}, log ticks with fixed point,% ]% \addplot table [timings] {\basepath/inline-loss-7.csv};% \addplot table [timings] {\basepath/inline-loss-1.csv};% \end{semilogyaxis}% \end{filecontents} \begin{document} \begin{figure}[ht]% \centering% \begin{subfigure}{.49\textwidth}% \centering% \sizedplot{.}{inline-rmse.tikz}% \end{subfigure}\hfill% \begin{subfigure}{.49\textwidth}% \centering% \sizedplot{.}{inline-timings.tikz}% \end{subfigure}\\[1pt]% \pgfplotslegendfromname{plot-loss}% \caption{Blah, blah, blah.}% \label{fig/losses}% \end{figure}% \end{document} Passing include context in ccmemo and trace both helped me discover memoize does not expand the macro \fullpath when trying to memoize the second graph (inline-timings.tikz). Instead, it only receives this bit of code to generate the hash: Code: \IfBooleanTF {\BooleanFalse }{\begin {tikzpicture}\input {\fullpath }\end {tikzpicture}}{\resizebox {\textwidth }{!}{\begin {tikzpicture}\input {\fullpath }\end {tikzpicture}}} And since it is the same for both pictures, this means the second graph (encountered later) will be saved under the "common" hash when compiling for the first time, leading to the graphs being the same on the final PDF... Now that I've discovered the cause, I need to dig deeper into why it happens 🙂
- PGFPlots / TikZ: Filtering data from a file when the x-axis contains string valuesby joseldsm on June 10, 2026 at 9:57 am
I am generating a plot in PGFPlots/TikZ where the x-axis contains string values and the y-axis contains numerical data. The data is imported from a CSV file, and everything works correctly so far. However, when I use skip coordinates between index, the filtering is applied to the y-values and not to the x-axis categories. In this case, I want to draw only the data with the string value B. Is there a way to correctly apply this filtering to both x-axis ? Thanks! Here is the MWE. Keep in mind that in my case the data are extract from csv file. \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotsset{compat=1.18} \pgfplotstableread{ String Value A 0 A 6 A 4 B 9 B 5 B 1 B 3 B 7 C 4 C 7 C 9 C 3 }\data \begin{document} \begin{tikzpicture} \begin{axis}[ ybar, ymin=0, xtick=data, xticklabels from table={\data}{String}, nodes near coords ] \addplot table[ x expr=\coordindex, y={Value}, skip coords between index={0}{3}, skip coords between index={8}{100} ]{\data}; \end{axis} \end{tikzpicture} \end{document}
- How to make 3D axes pass above/below a surface in pgfplotsby UnknownW on May 25, 2026 at 11:54 pm
I am trying to draw a 3D graph that looks like the attached picture. However, I cannot make the axes behave in the same way. In the picture, some intervals of the axes appear on top of the surface, while on other intervals the surface appears above the axes. I would also like the axis labels to stay outside the arrow tips. What I have tried so far is shown below, together with the attached picture. I would like a solution that works for arbitrary functions, not only for this particular example. \documentclass[tikz,border=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ view={45}{20}, axis lines=center, %axis on top, axis line style={-latex}, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, ticks=none, xmin=-5, xmax=5, ymin=-5, ymax=5, zmin=-4, zmax=4, width=7cm, height=7cm, colormap/jet, declare function={ f(\x,\y)=10*\y/((\x^2 + 1)*(\y^2 + 2*\y + 4)); }, ] \addplot3[ surf, opacity=0.6, faceted color=black!80, samples=60, samples y=60, domain=-4:4, y domain=-4:4, line width=0.01pt, ] (({x},{y},{f(x,y)}); \end{axis} \end{tikzpicture} \end{document}
- Sequence of functions: easing packageby Sebastiano on May 23, 2026 at 8:20 pm
I was trying to understand how the easing package works and whether it can be useful for plotting a sequence of functions in order to study uniform convergence. I am not sure whether the package only allows plotting a set of predefined functions, or whether it also enables the representation of arbitrary sequences of functions. In particular, I would like to know whether there is a way to use this package (or other similar LaTeX packages) to effectively visualize any sequence of functions. If there is a more suitable tool, I would appreciate it if you could suggest it. Additionally I not understand the reason of a ugly graph for $n=1, 2$. Here an example: \documentclass{article} \usepackage{pgfplots} \usepgflibrary{easing} \pgfplotsset{compat=1.18} \begin{document} \begin{center} \begin{tikzpicture} \begin{axis}[ width=12cm, height=7cm, domain=0:1, axis equal image, samples=300, xmin=0, xmax=1, ymin=0, ymax=1.05, axis lines=left, xlabel={$x$}, ylabel={$x^n$}, legend pos=north west, thick ] \pgfkeys{/easing/pow/exponent=1} \addplot[blue] {poweasein(0,1,x)}; \addlegendentry{$n=1$} \pgfkeys{/easing/pow/exponent=2} \addplot[red] {poweasein(0,1,x)}; \addlegendentry{$n=2$} \pgfkeys{/easing/pow/exponent=4} \addplot[green!60!black] {poweasein(0,1,x)}; \addlegendentry{$n=4$} \pgfkeys{/easing/pow/exponent=8} \addplot[orange] {poweasein(0,1,x)}; \addlegendentry{$n=8$} \addplot[black, dotted] { (x==1 ? 1 : 0) }; \addlegendentry{$\lim f_n$} \end{axis} \end{tikzpicture} \end{center} \end{document}
- (Semi-)Globally set `table` options in `\addplot table`?by Denis Bitouzé on May 21, 2026 at 7:36 am
Suppose I need to plot data from many files using pgfplots, and these files are not properly formatted (8 header lines not prefixed with % or #, and commas instead of periods as decimal separators). This can be managed using the following code: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis} \addplot table [skip first n=8,/pgf/number format/read comma as period] {data1.dat}; \addplot table [skip first n=8,/pgf/number format/read comma as period] {data2.dat}; \end{axis} \end{tikzpicture} \end{document} But it is tedious to have to specify these table options each time \addplot table appears. I haven't found any way in the pgfplots documentation to declare these parameters in a (semi-)global manner. Have I missed something?
- Tangential curve labels with 1D force-based collision avoidance along paths in pgfplotsby cjorssen on May 17, 2026 at 8:44 pm
I am trying to implement a dynamic labeling system for multiple curves within a pgfplots axis environment. The goal is to have curve labels that are both tangential (sloped) to their respective paths and capable of avoiding collisions by utilizing a 1D force-based relaxation mechanism to repel each other along the curves' domains. My Understanding of pgfplots Internals From what I understand of pgfplots internals, and please correct me if my assumption is flawed, the package operates on a deferred drawing (or accumulation) model, conceptually quite similar to how matplotlib handles figures in Python. It seems to split its workflow into distinct steps: A Survey Phase where it reads \addplot data, accumulates coordinates in memory, and computes the global axis limits. A Visualization Phase triggered at \end{axis} where it maps data coordinates to physical dimensions and emits the actual TikZ paths and nodes. Based on this understanding, it feels like the ideal place to inject a label-relaxation algorithm would be right between these two phases (perhaps using hooks like before end axis), after the data is parsed but before the final typesetting occurs. The Technical Bottleneck: The Node Bounding Box Dilemma The core difficulty I am facing is a classic "chicken-and-egg" problem: To know the dimensions (width, height, depth) of a label's bounding box for collision detection, TeX must first typeset the text into a box. However, we cannot definitively position or rotate that node along the path until the force-based algorithm has computed the final, relaxed $t$ parameters for all curves. If a LuaLaTeX-based approach is required to handle the physics/loop, I am completely open to it. But I am unsure how to elegantly pass TeX box dimensions into Lua, or how to query the generated curve paths before the rendering phase. Minimal Working Example (Current State) Here is a basic MWE where the labels are sloped but completely overlap: \documentclass[border=5mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ domain=0:3.5, restrict y to domain = 0:10, samples=100, axis lines=left ] % Curve 1 \addplot[blue, thick] {x^2} node[pos = 0.2, sloped] {Function $f(x)$}; % Curve 2 \addplot[red, thick] {1/x} node[pos = 0.8, sloped] {Function $g(x)$}; \end{axis} \end{tikzpicture} \end{document} Tentative Logic / Pseudo-code (Force-Based Relaxation) Ideally, the macro or Lua script would perform a spring-embedder / force-directed approach constrained to 1D path coordinates: # Pre-computation phase for each label L_i: Typeset L_i into a temporary TeX box to get its dimensions (W_i, H_i) # Force-directed loop while system_not_in_equilibrium and max_iterations_not_reached: Initialize forces F_i = 0 for all labels for each curve i with label L_i: 1. Get baseline position P_i = curve_i(t_i) 2. Compute tangent angle theta_i at t_i 3. Construct Label Bounding Box B_i (using W_i, H_i) at P_i rotated by theta_i for each pair of labels (L_i, L_j): if Intersect(B_i, B_j): # Compute repulsive force based on overlap magnitude force_magnitude = calculate_repulsive_force(B_i, B_j) # Project force along the 1D direction of the respective curves F_i = F_i - force_magnitude F_j = F_j + force_magnitude # Update positions using a small step size (damping) for each label L_i: t_i = t_i + alpha * F_i ConstraintToValidDomain(t_i) Questions & Directions Is my mental model of the pgfplots accumulation process accurate enough to build upon, or am I missing a fundamental constraint of the package architecture? Is there an existing package or experimental snippet that already handles force-based label placement or relaxation algorithms along TikZ paths? If doing this via LuaLaTeX, what is the cleanest way to intercept the path coordinates generated by pgfplots and pass the TeX box dimensions to a Lua-based physics loop? Any pointers, conceptual corrections, or architectural advice would be highly appreciated. Real-World Use Case (Thermodynamic Diagrams) To provide some concrete context on why this automation is so critical for my workflow, here is a screenshot of the type of complex diagram I am currently generating (with luatex, FFI and the CoolProp shared library). It is a pressure-enthalpy (p-h) diagram widely used in refrigeration and chemical engineering, plotted in the (p, log h) plane for a pure substance. As you can see, the visual density is extremely high because it overlays several distinct families of isolines crossing each other: Isotherms (constant temperature) Isentropes (constant entropy) Isochores (constant specific volume) Vapor quality lines / isotitres (constant dryness fraction) Manually hardcoding and fine-tuning the pos parameter for dozens of labels across these intersecting families of curves is completely unmanageable—especially since the curves shift dramatically depending on the thermodynamic properties of the fluid being modeled. Having a generalized, tangential, force-directed algorithm to let these labels dynamically find their equilibrium along their respective paths would be an absolute game-changer for rendering complex engineering charts natively in pgfplots.
- How to plot y = x^{2/3} + 0.8 cos(kx) √(3-x²) in LaTeX TikZby hola on April 7, 2026 at 1:45 pm
I would like to plot the following function in LaTeX using TikZ or pgfplots: \[ y = x^{2/3} + 0.8 \cdot \cos(kx) \cdot \sqrt{3 - x^2} \] The domain is \( - \sqrt{3} \leq x \leq \sqrt{3} \). I need to create a nice graph where: The curve looks smooth I can easily change the value of \( k \) (number of oscillations) The modulated amplitude (the \( \sqrt{3-x^2} \) part) is clearly visible I have tried basic \addplot but I have problems with the fractional power \( x^{2/3} \) and with making the cosine oscillation look good. MWE (Minimal Working Example): \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis} \addplot {x^(2/3)}; % this part works, but adding the rest is difficult \end{axis} \end{tikzpicture} \end{document} pgfplots tikz-pgf plot functions graphics
- How to improve graphs of functions of two variables with jagged edges in pgfplots?by orion2112 on January 9, 2026 at 10:19 pm
In the spirit of creating "beautiful plots" of functions of two variables, I am reaching out to this community to try and find possible improvements in the way I have been using pgfplots and \addplot3. Here are 3 attempts at graphing the paraboloid $f(x,y)=x^2+y^2$. Attempt 1: plotting {x^2+y^2} in cartesian coordinates with no restriction on the z domain yields a plot that "hides part of itself" and doesn't readily show the "bowl" shape we all love: \documentclass[tikz,12pt]{standalone} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{colorbrewer} %For the colormap \begin{document} \begin{tikzpicture} \begin{axis}[ axis line style={very thick}, axis on top=false, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, zlabel style={rotate=90}, xtick={-3,-2,-1,0,1,2,3}, ytick={-3,-2,-1,0,1,2,3}, ztick={-3,-2,-1,0,1,2,3}, tick label style={font=\scriptsize}, no marks, xmin=-3, xmax=3, ymin=-3, ymax=3, zmin=-3, zmax=3, view={130}{30}, title={Smooth and ugly} ] \addplot3[ surf, samples=40, colormap/PuBu-9, shader=flat, domain=-3:3, y domain=-3:3, opacity=0.5 ] {x^2+y^2}; \end{axis} \end{tikzpicture} \end{document} Attempt 2: adding the "restrict z to domain=-3:3" option, but this produces a very jagged top edge to the paraboloid, and not a nice smooth circle. Adding samples reduces the jaggedness slightly but there is a limit to how many samples I can put before I get an error, and that isn't enough to get a smooth circle. \documentclass[tikz,12pt]{standalone} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{colorbrewer} %For the colormap \begin{document} \begin{tikzpicture} \begin{axis}[ axis line style={very thick}, axis on top=false, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, zlabel style={rotate=90}, xtick={-3,-2,-1,0,1,2,3}, ytick={-3,-2,-1,0,1,2,3}, ztick={-3,-2,-1,0,1,2,3}, tick label style={font=\scriptsize}, no marks, xmin=-3, xmax=3, ymin=-3, ymax=3, zmin=-3, zmax=3, view={130}{30}, title={Jagged edges at top} ] \addplot3[ surf, samples=40, colormap/PuBu-9, shader=flat, domain=-3:3, y domain=-3:3, restrict z to domain={-3:3}, opacity=0.5 ] {x^2+y^2}; \end{axis} \end{tikzpicture} \end{document} Attempt 3: using data cs=polar and a domain of 0:360 instead of -3:3 gets me to an acceptable graph that doesn't hide itself and that has a smooth border: \documentclass[tikz,12pt]{standalone} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{colorbrewer} %For the colormap \begin{document} \begin{tikzpicture} \begin{axis}[ axis line style={very thick}, axis on top=false, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, zlabel style={rotate=90}, xtick={-3,-2,-1,0,1,2,3}, ytick={-3,-2,-1,0,1,2,3}, ztick={-3,-2,-1,0,1,2,3}, tick label style={font=\scriptsize}, no marks, xmin=-3, xmax=3, ymin=-3, ymax=3, zmin=-3, zmax=3, view={130}{30}, title={Not jagged, but polar coords} ] \addplot3[ surf, samples=40, colormap/PuBu-9, shader=flat, data cs=polar, domain=0:360, y domain=-3:3, restrict z to domain={-3:3}, opacity=0.5 ] ({x},{y},{y^2}); \end{axis} \end{tikzpicture} \end{document} Problem solved? Not really. What if now I want to plot f(x,y)=x/(y-x)? If done in cartesian coordinates without restricting the z domain, the graph "hides itself". If done in cartesian coordinates and restricting the z domain, some of the edges are jagged. For instance: (I seem to notice that if the mesh line is parallel to one of the "walls" of the plot box, there is no jagged edge, but if a "square" of the mesh is outside the z domain, the whole square is erased, and not just the part that is outside the z domain). And here I don't see how polar coordinates would be usable to bypass that problem. "But, this is not a nice function, of course the graph will be ugly". Fair enough, but seeing that Desmos does it instantly and even allows you to rotate the plot smoothly, I was hoping that maybe it's possible to do better here: So, is there anything that can be done about this? Am I using this wrong? Or is it just a limitation of plotting surfaces in LaTeX? Thanks in advance for all the insight. Note: I am aware of the topic here and that it seems there are only rectangular (and not triangular) surface elements, but I am not sure the issue is the same nor how \clip and \begin{scope} were used to fix the issue. If this is the way to go, can someone explain what those commands do exactly?
- Clip in tikz-3dplotby Angelo Aliano Filho on March 9, 2025 at 9:34 pm
I have the code below working perfectly: \documentclass[tikz,border=0mm]{standalone} \usepackage{tikz-3dplot} \definecolor{vinho}{rgb}{0.0, 0.26, 0.15} \usepackage{xfp} \newcommand{\ar}[1]{\fpeval{round(#1,2)}} \usetikzlibrary{positioning} \begin{document} \tdplotsetmaincoords{75}{120} \foreach \ang in {45}{ \begin{tikzpicture}[tdplot_main_coords,font=\small] \draw[-latex] (0,0,0) -- (4,0,0) node[below left]{$x$}; \draw[-latex] (0,0,0) -- (0,4,0) node[right]{$y$}; \draw[-latex] (0,0,0) -- (0,0,4) node[above]{$z$}; \draw[dashed] (0,0,0) -- (-4,0,0) (0,0,0) -- (0,-4,0) (0,0,0) -- (0,0,-2.5); \draw[fill,gray,opacity=0.1] (-4,-4,0) -- (-4,4,0) -- (4,4,0) -- (4,-4,0) -- cycle; \foreach \Rmax in {0,0.025,...,0.95,1}{ \draw[opacity=0.15,samples=50,smooth,domain=0:360,vinho,line width=0.7pt] plot({2*sqrt(2)*\Rmax*cos(\x)},{sqrt(2)*\Rmax*sin(\x)},{2-2*\Rmax^2}); } \foreach \Tmax in {0,5,...,360}{ \draw[opacity=0.15,samples=50,smooth,domain=0:1,vinho,line width=0.7pt] plot({2*sqrt(2)*\x*cos(\Tmax)},{sqrt(2)*\x*sin(\Tmax)},{2-2*\x^2}); } % \coordinate (P0) at (1,1,0.75); \coordinate (P1) at ({3*cos(\ang)},{3*sin(\ang)},-0.5); \coordinate (P2) at ({-3*cos(\ang)},{-3*sin(\ang)},-0.5); \coordinate (P3) at ({-3*cos(\ang)},{-3*sin(\ang)},1.5); \coordinate (P4) at ({3*cos(\ang)},{3*sin(\ang)},1.5); \draw[vinho,fill,fill opacity=0.05] (P1) -- (P2) -- (P3) -- (P4) -- cycle; % \draw[-latex,blue,thick] (0,0,0) -- ({1.5*cos(\ang)},{1.5*sin(\ang)},{0}) node[below right] {$\mathbf{u}$}; \draw[-latex,red] (P0) -- +({cos(\ang)},{sin(\ang)},{-0.5*cos(\ang)-2*sin(\ang)}) node[right=-2pt] {$\frac{\partial f}{\partial \mathbf{u}}$}; %Cut the parabola with zmin here..... \draw[black,smooth,domain=-2:2,samples=100,thick] plot({\x},{(-sin(\ang)+cos(\ang)+sin(\ang)*(\x))/cos(\ang)},{2-0.25*(\x)^2 -((-sin(\ang)+cos(\ang)+sin(\ang)*(\x))/cos(\ang))^2}); % \fill (P0) node[above] {\scalebox{0.8}{$P_0$}} circle (2pt); \node[name=funcao,anchor=west] at (1,5,3) {$f(x,y) = 2-\frac{x^2}{4} - y^2$}; \node[name=P,below=1cm of funcao.west,anchor=west] {$P_0=(1,1)$ e $\mathbf{u} = (\cos \ar{\ang}º,\sin \ar{\ang}º)$}; \node[,below=1cm of P.west,anchor=west] {$\frac{\partial f}{\partial \mathbf{u}} (P_0) = \ar{-0.5*cos(\ang*pi/180)-2*sin(\ang*pi/180)}$}; \end{tikzpicture} } \end{document} Whose output is the following: However, I would like to cut the image with a given zmin (for example, cut from zmin=-1). How can I do this with tikz-3dplot. I have tried with clip command but I don't get the desired result.
- Adding a diagram to a chartby Nicolas on December 28, 2024 at 12:12 am
I would like to be able to have this type of graph: \documentclass{standalone} \usepackage[dvipsnames,svgnames]{xcolor} \usepackage{lmodern} %\mathcode`\.="013B%virgule décimale en mode math %\usepackage{tikz}% chargé automatiquement par pgfplots \usepackage{pgfplots}\pgfplotsset{compat=newest} \pgfplotsset{/pgf/number format/.cd,1000 sep={~},use comma} \pgfplotsset{compat=newest} % Permet l'affichage de deux axes y \usetikzlibrary{tikzmark} \usepackage[all]{chemmacros} \usepackage{siunitx} \begin{document} \begin{tikzpicture} \begin{axis}[% mise en forme du graphique : xmin=-10,xmax=400, ymin=-2,ymax=50.1, % <<< samples = 100, no markers, axis x line=bottom,axis y line = left, ylabel={$E_p (\unit{\kJ\per\mol})$}, xlabel={$\theta (\unit{\degree})$}, xtick={0,60,120,180,240,300,360}, ytick=\empty, ] \addplot[mark=none, draw=blue] expression[domain=0:360,samples=100]{5*cos(3*x)+25}; \end{axis} \end{tikzpicture}% \newman(0){} \newman(62){} \newman(120){} \newman(180){} \newman(240){} \newman(300){} \end{document}
- pgfplots / 2D contour filled plot from a csv fileby TheBeeTee on December 1, 2024 at 11:19 pm
Trying to plot a 2D colormap of my data like this: Here's my MWE with a sample of data. x,y are the coordinates. P is the value on which I want to base the shading. \documentclass[border=1 cm]{standalone} \usepackage{pgfplots} \begin{document} \begin{filecontents}{test.csv} x,y,P 0.6029680189,0.7383407645,2.3729000000 0.5323565117,0.6601831742,3.2726000000 0.4677196601,0.5882540709,4.0038000000 0.0946800948,0.6688882286,5.0510000000 0.1884371445,0.6355349568,5.0222000000 0.2792665104,0.5997515545,4.8900000000 0.3623180375,0.5641482523,4.6771000000 0.4853625211,0.1178246418,5.0150000000 0.4696592171,0.2354673908,4.9738000000 0.4525723312,0.3510530681,4.8490000000 0.4353225341,0.4584688067,4.6566000000 \end{filecontents} \begin{tikzpicture} \begin{axis}[ view = {0}{90}, colorbar, ] \addplot3[ contour filled={number = 20} ] table[x=x, y=y, z=P, col sep=comma]{test.csv}; \end{axis} \end{tikzpicture} \end{document} The code above was throwing: ERROR: shader=interp: got unsupported pdf shading type '0'. *****After more searching, I modified my MWE as follows. I don't get any errors, I just get an empty plot 🙁 \documentclass[border=1 cm]{standalone} \usepackage{pgfplots} \usepgfplotslibrary{patchplots} \begin{document} \begin{filecontents}{test.csv} x,y,P 0.6029680189,0.7383407645,2.3729000000 0.5323565117,0.6601831742,3.2726000000 0.4677196601,0.5882540709,4.0038000000 0.0946800948,0.6688882286,5.0510000000 0.1884371445,0.6355349568,5.0222000000 0.2792665104,0.5997515545,4.8900000000 0.3623180375,0.5641482523,4.6771000000 0.4853625211,0.1178246418,5.0150000000 0.4696592171,0.2354673908,4.9738000000 0.4525723312,0.3510530681,4.8490000000 0.4353225341,0.4584688067,4.6566000000 \end{filecontents} \begin{tikzpicture} \begin{axis}[ %view = {0}{90}, colorbar, ] \addplot[contour filled={number = 8,labels={false}}, mesh/rows=100,mesh/cols=100,mesh/check=false, patch type=bilinear, point meta=explicit, ] table [x=x, y=y, z=P, col sep=comma]{test.csv}; \end{axis} \end{tikzpicture} \end{document}
- How to add space between x axis labels and draw a vertical line after a set of IDs?by Student on November 21, 2024 at 8:13 pm
I'm trying to add space between x axis labels 10 Flows, 20 Flows, and 30 Flows and also properly draw a line after for every 1 to 8 IDs. Could someone help me with this problem? Code: % restructured data file: % - 'n' values are sorted ascending % - added column 'z' to know which data belong to which measurement % - added a dummy line at the end of each data set to produce an empty entry % for the separation of the blocks % - put all data in one file \begin{filecontents}{data.txt} z n pFA pFB 10 1 6 1 10 2 7 1 10 3 8 4 10 4 9 7 10 5 10 9 10 6 0 0 10 7 9 4 10 8 12 6 20 1 6 1 20 2 7 1 20 3 8 4 20 4 9 7 20 5 10 9 20 6 0 0 20 7 9 4 20 8 12 6 30 1 6 1 30 2 7 1 30 3 8 4 30 4 9 7 30 5 10 9 30 6 0 0 30 7 9 4 30 8 12 6 \end{filecontents} \documentclass[border=5pt]{standalone} \usepackage{pgfplots} \usetikzlibrary{patterns} \pgfplotsset{compat=1.3} \begin{document} \begin{tikzpicture} \begin{axis}[ footnotesize, % set the `width' of the plot to the maximum length ... width=\textwidth, % ... and use half this length for the `height' height=0.5\textwidth, ymin=0, ymax=100, %yticklabel=\pgfmathprintnumber{\tick}\,$\%$, % use `data' for the positioning of the `xticks' ... xtick=data, % ... and use table data for labeling the `xticks' xticklabels from table={data.txt}{n}, % add extra ticks "at the empty entries to add the vertical lines extra x ticks={8,16}, % this ticks shouldn't be labeled ... extra x tick labels={}, % ... but grid lines should be drawn without the tick lines extra x tick style={ grid=major, major tick length=0pt, }, xlabel={X Axis Label}, ylabel={Y Axis Label}, % because of the category labels, shift the `xlabel' a bit down xlabel style={ yshift=-4ex, }, legend pos=north west, legend entries={ {\color{black}{Algorithm A}}, {\color{red}{Algorithm B}}, }, area legend, % adjust `bar width' so it fits your needs ... bar width=10pt, % ... and with that you also have to adjust the x limits enlarge x limits=0.05, % set `clip mode' to `individual' so the category labels aren't clipped away clip mode=individual, ] % plot the "red" ybars \addplot [ ybar, draw=black, pattern color=black, pattern=dots, ] table [ % use just the `coordindex' as x coordinate, % the correct labeling is done with `xticklabels from table' x expr=\coordindex, y=pFA, ] {data.txt}; % plot the "blue" ybars \addplot [ ybar, draw=red, pattern color=red, pattern=north east lines, ] table [ x expr=\coordindex, y=pFB, ] {data.txt}; % add the category labels \begin{scope}[ % because the reference point will be the lower axis line the % labels have to be moved a bit more down to don't overlap with % the `xticklabels' every label/.append style={ label distance=2ex, }, ] \node [label=below:10 Flows] at (axis cs:4,\pgfkeysvalueof{/pgfplots/ymin}) {}; \node [label=below:20 Flows] at (axis cs:12,\pgfkeysvalueof{/pgfplots/ymin}) {}; \node [label=below:30 Flows] at (axis cs:20,\pgfkeysvalueof{/pgfplots/ymin}) {}; % \node [label=below:40 Flows] % at (axis cs:20,\pgfkeysvalueof{/pgfplots/ymin}) {}; %\node [label=below:50 Flows] % at (axis cs:26,\pgfkeysvalueof{/pgfplots/ymin}) {}; \end{scope} \end{axis} \end{tikzpicture} \end{document} Output:
- Prevent connection of ends of a partial circle in a 3D tikz pictureby Melissa on April 3, 2024 at 5:00 pm
I want to draw a 3-dimensional parabola (i.e. plot $z=x^2 + y^2$) with maximal value of z=1 and then mark the part of the parabola where $x^2 + y^2 =1$, $x\leq 0$ and $y \leq 0$, which is part of a circle. I have the following code: \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture}[radius=1] \begin{axis}[ xlabel=$l_1$, ylabel=$l_2$, zlabel=$u$, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-0.1, zmax=1.05, % x={(-0.125cm,-0.05cm)}, % y={(0.125cm,-0.05cm)}, % z={(0cm,0.05cm)}, axis lines=middle, every axis x label/.style={ at={(ticklabel* cs:1.05)}, }, every axis y label/.style={ at={(ticklabel* cs:1.05)}, }, every axis z label/.style={ at={(ticklabel* cs:1.05)}, }, colormap/blackwhite,] % Paraboloid \addplot3[ surf, samples=50, shader=interp, draw=lightgray, ultra thin, opacity=0.5, fill opacity=0.5, data cs=polar, domain=0:360, y domain=0:1, restrict z to domain=0:1, ](x, y, y^2); % Part of parabola \addplot3[ surf, samples=50, shader=interp, draw=lightgray, fill=green, ultra thin, left color=green, right color=green, middle color=green!25, data cs=polar, domain=180:270, y domain=0:1, restrict z to domain=0:1, ](x, y, y^2); %partial circle \addplot3[ domain=180:270, samples=20, variable=\t, color=red, untra thin, ] ({cos(\t)}, {sin(\t)}, {1}); \end{axis} \end{tikzpicture} \end{document} I do not want to connect the end points of the partial circle. How do I prevent this from happening?
- types of systems of linear equations and intersection of planes, with tikzby Juan Leal on July 22, 2023 at 2:57 pm
Is there a simple way using tikz to graph a plane from its equation (like those of the systems on the right side, e.g. 2x +3y -z = 11), and that allows me to represent the intersection of two or three of them (even four)? If possible, I additionally need it to allow me to have flat colors in each of the planes involved and not to be represented by pieces as suggested by some of the solutions I have seen. I want to represent graphically to my students all the possibilities that can be presented with a system of linear equations with three unknowns, in a way similar to the one in the image I include. I have been reading the material related to this topic for three days and I have not found a completely satisfactory solution (or maybe there is one, but I have not appreciated it properly). I know a bit about tikz, pgfplots and tikz-3dplot (and I come from the old school of pstricks).
- How to plot the 3D graph of the following three inequalities in latex (e.g., tikz/pgf)?by learner on July 9, 2021 at 9:27 am
How to plot the 3D graph of the following three inequalities in latex (tikz/pgf) ? z <= x+y+1, z <= 4x, z <= 5y. My attempt: \documentclass[12pt,leqno]{amsart} \usepackage{pgfplots} \usepackage{tikz} \begin{document} \begin{tikzpicture} \begin{axis} \addplot3 [ domain=-5:20, domain y = -3:10, samples = 20, samples y = 8, surf] {x+y+1}; \addplot3[domain=-5:20, domain y = -3:10, samples = 20, samples y = 8, surf, opacity=0.25]{4*x}; \addplot3[domain=-5:20, domain y = -3:10, samples = 20, samples y = 8, surf, opacity=0.25]{5*y}; \end{axis} \end{tikzpicture} \end{document} The above Latex code produces the above figure: But the above graph is not clear, the intersecting line of the three half-planes are not clear. Any help to draw clear image with clear intersection. Any help both with the 3D graph of the given 3 inequalities. Thanks Edit: The 2D projection of the above 3 inequalities becomes: and this is justified by the answer of @Juan Castaño.
- How do I crop a 3D surface in pgfplots?by Lucas Abounader on February 20, 2021 at 2:00 am
I am attempting to reproduce the following graph using pgfplots: Here is the MWE code I developed, along with the corresponding plot generated: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{pgfplots} \pgfplotsset{compat=1.17} \begin{document} \begin{center} \begin{tikzpicture} \begin{axis}[ width=8cm, height=12cm, axis lines=center, view={120}{30}, mesh/interior colormap name=hot, colormap/cool, point meta min=0.5, point meta max=6, xmin=-2, xmax=2, xlabel=\Large{$s$}, ymin=-0.5, ymax=2.5, ylabel=\large{$t$}, zmin=0, zmax=6, ] \addplot3[ surf, shader=interp, samples=50, domain=-2:2, y domain=-0.5:2.5 ] {14*x*x+20*x*y-22*x+11*y*y-24*y+14}; \end{axis} \end{tikzpicture} \end{center} \end{document} There are a few issues: The view box does not crop the plot as I would like. I am looking for the elliptic intersection with the plane z=6 akin to the first image. The interior surface (colored by mesh/interior colormap name=hot) is not visible. pgfplots is giving the following warning: Package pgfplots Warning: the combination 'shader=interp,interior colormap name ' is inefficient (it uses 'shader=faceted interp,faceted color=none') and may s low down the *display* of your document on input line 44. I only know the command shader=interp to remove mesh gridlines and I would like to shade the interior and exterior surfaces with different colormaps. What is going on? How can I get the desired "crop" effect? For reference, here is the surface rendered with gridlines:
- Alignment of pgfplots inside subfloats when using tikzplotlibby Marvin Noll on December 4, 2020 at 10:58 pm
I'm using the tikzplotlib code below to generate two Plots. I then place them in two subfloats. As you can see in the final latex output, the figure looks rather ugly with the two plots differently sized and not aligned. What can i do to achieve the same size of the plots and to align them properly. Maybe worth noting, i have several of these figures with multiple subfloats in my document. Python: import matplotlib.pyplot as plt import tikzplotlib import numpy as np x1=np.arange(0,10)*10e9 x2=np.arange(0,1000) y1=np.random.randn(1,len(x1))[0] y2=0.01*x2*np.random.randn(1,len(x2))[0] KIT_green=(0/255,150/255,130/255) KIT_blue=(70/255,100/255,170/255) plt.figure() plt.plot(x2,y2,label="second trace",color=KIT_green) plt.xlabel(r"Time $t$ (in \si{\milli\second})") plt.ylabel(r"Amplitude $S_{11}$ \\ (some measurement) \\ (and another meaningless line) (in \si{\volt})"); tikzplotlib.save("subfigs_left.tikz",extra_axis_parameters=["ylabel style={align=center}"],axis_width="5cm",axis_height="5cm") plt.figure() plt.plot(x1,y1,label="first trace",color=KIT_blue) plt.xlabel(r"Time $t$ (in \si{\milli\second})") plt.ylabel(r"Amplitude $S_{11}$, $S_{35}$ (in \si{\volt})"); tikzplotlib.save("subfigs_right.tikz",extra_axis_parameters=["ylabel style={align=center}"],axis_width="5cm",axis_height="5cm") LaTeX: \documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage{graphicx} \usepackage{subfig} \usepackage{siunitx} \usepackage{tikz} \usepackage{pgfplots} \usepackage{tikzscale} \begin{document} \begin{figure} \centering \subfloat[Plot 1: this shows this]{\includegraphics[width=0.4\textwidth]{subfigs_left.tikz}} \qquad \subfloat[Plot 2: and this shows that. But this explanation is quite long. blablabla]{\includegraphics[width=0.4\textwidth]{subfigs_right.tikz}} \caption{Two plots} \label{fig:subfig} \end{figure} \end{document}
- TikZ plot for Enneper's minimal surface?by Yiannis I on November 9, 2020 at 12:41 pm
Is there a way to plot Enneper's minimal surface in TikZ either using its implicit equation or its parameterized form? ref:https://mathworld.wolfram.com/EnnepersMinimalSurface.html
- Multiple 2D Gaussian ellipses in 3D plotby dodi on March 19, 2019 at 12:30 pm
I'd like to plot different bivariate Gaussian distributions as shaded 2D ellipses at different points in 3D space. The 2D ellipses I would plot like Jake suggests in Gaussian ellipsoids using tikz, but technically that is already a 3D plot. Is there a possibility to extend this method? I came up with the following example (left: example how I like the ellipses to be orientated, taken from https://arxiv.org/abs/1611.03986, right: my ansatz): Two main points are that the colormap is not actually transparent and one cannot see the axis of the outer coordinate system any more, and that I would like to have the ellipses at a fixed point y in the xz-plane (this means that the bottom line of the black rectangles should be parallel to the x-axis and compressed accordingly). \documentclass{standalone} \usepackage{tikz,pgfplots} \usepgfplotslibrary{patchplots} \pgfplotsset{% colormap={whitered}{color(0cm)=(transparent); color(1.cm)=(red)}% } \begin{document} \begin{tikzpicture}[baseline, declare function={bivar(\ma,\sa,\mb,\sb)= 1/(2*pi*\sa*\sb) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2))/2;}] % Outer coordinate system \begin{axis}[ unit vector ratio*=1 1 1, axis lines = middle, view={120}{30}, domain = -10:10, zmin = -5, zmax = 5, xlabel = $x$, ylabel = $y$, zlabel = $z$, x label style={at={(ticklabel* cs:1.)},anchor=north east}, y label style={at={(ticklabel* cs:1.)},anchor=north west}, z label style={at={(ticklabel* cs:1.)},anchor=south}, ] \coordinate (origin1) at (axis cs:0,-10,0); \coordinate (origin2) at (axis cs:0,10,0); \addplot3[no markers,opacity=0]{0}; % <- without this pseudo plot, the outer coordinate system does not work \end{axis} % Bivariate distribution 1 \begin{axis}[ at={(origin1)}, anchor={center}, width=3cm, height=3cm, scale only axis, axis equal image, hide axis, colormap name=whitered, view={0}{90}, enlargelimits=false, domain=-1.5:1.5, y domain=-1.5:1.5, ] \addplot3 [surf, draw=none, samples=19, shader=interp, patch type=bilinear] {bivar(0,.1,0,.6)}; \end{axis} % Bivariate distribution 2 \begin{axis}[ at={(origin2)}, anchor={center}, width=3cm, height=3cm, scale only axis, axis equal image, hide axis, colormap name=whitered, view={0}{90}, enlargelimits=false, domain=-1.5:1.5, y domain=-1.5:1.5, ] \addplot3 [surf, draw=none, samples=19, shader=interp, patch type=bilinear] {bivar(0,.2,0,.3)}; \end{axis} \end{tikzpicture} \end{document}
- PGFPlot 3D opacity and appearanceby Gabriel Pino on January 11, 2018 at 10:02 pm
I used MATLAB to generate some 3D figures and I would like to show two surfaces in one graphic using PGFPlots. In order to better illustrate the surface differences, I set opacity = 0.5 for both of them. The matlab figure perfectly shows the spots where the blue function is greater than the red one, as you can see below. The PGFplot is a little bit different: I have already tried matlab2tikz and it did not work very well. What can I do to improve my TeX code? \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{decorations.text,arrows} \usepackage{pgfplots} \usepackage{animate} \pgfplotsset{compat=1.15} \usepgfplotslibrary{colormaps} \pgfplotsset{colormap={prop}{ rgb255=(1,1,255) rgb255=(10, 10, 255) }} \pgfplotsset{colormap={berg}{ rgb255=(255,1,1) rgb255=(255, 10, 10) }} \begin{filecontents}{TPTC.dat} -5.0000000e+00 -5.0000000e+00 0.0000000e+00 8.3333333e-02 -5.0000000e+00 -4.0000000e+00 0.0000000e+00 1.6666667e-01 -5.0000000e+00 -3.0000000e+00 8.3333333e-02 8.3333333e-02 -5.0000000e+00 -2.0000000e+00 0.0000000e+00 1.6666667e-01 -5.0000000e+00 -1.0000000e+00 8.3333333e-02 2.5000000e-01 -5.0000000e+00 0.0000000e+00 1.6666667e-01 2.5000000e-01 -5.0000000e+00 1.0000000e+00 8.3333333e-02 8.3333333e-02 -5.0000000e+00 2.0000000e+00 8.3333333e-02 1.6666667e-01 -5.0000000e+00 3.0000000e+00 8.3333333e-02 3.3333333e-01 -5.0000000e+00 4.0000000e+00 2.5000000e-01 8.3333333e-02 -5.0000000e+00 5.0000000e+00 3.3333333e-01 2.5000000e-01 -4.0000000e+00 -5.0000000e+00 1.6666667e-01 1.6666667e-01 -4.0000000e+00 -4.0000000e+00 1.6666667e-01 1.6666667e-01 -4.0000000e+00 -3.0000000e+00 8.3333333e-02 8.3333333e-02 -4.0000000e+00 -2.0000000e+00 8.3333333e-02 2.5000000e-01 -4.0000000e+00 -1.0000000e+00 2.5000000e-01 3.3333333e-01 -4.0000000e+00 0.0000000e+00 8.3333333e-02 1.6666667e-01 -4.0000000e+00 1.0000000e+00 8.3333333e-02 2.5000000e-01 -4.0000000e+00 2.0000000e+00 0.0000000e+00 1.6666667e-01 -4.0000000e+00 3.0000000e+00 2.5000000e-01 8.3333333e-02 -4.0000000e+00 4.0000000e+00 2.5000000e-01 4.1666667e-01 -4.0000000e+00 5.0000000e+00 2.5000000e-01 4.1666667e-01 -3.0000000e+00 -5.0000000e+00 8.3333333e-02 8.3333333e-02 -3.0000000e+00 -4.0000000e+00 8.3333333e-02 0.0000000e+00 -3.0000000e+00 -3.0000000e+00 8.3333333e-02 2.5000000e-01 -3.0000000e+00 -2.0000000e+00 8.3333333e-02 8.3333333e-02 -3.0000000e+00 -1.0000000e+00 8.3333333e-02 2.5000000e-01 -3.0000000e+00 0.0000000e+00 8.3333333e-02 8.3333333e-02 -3.0000000e+00 1.0000000e+00 2.5000000e-01 8.3333333e-02 -3.0000000e+00 2.0000000e+00 2.5000000e-01 1.6666667e-01 -3.0000000e+00 3.0000000e+00 2.5000000e-01 2.5000000e-01 -3.0000000e+00 4.0000000e+00 3.3333333e-01 3.3333333e-01 -3.0000000e+00 5.0000000e+00 4.1666667e-01 7.5000000e-01 -2.0000000e+00 -5.0000000e+00 8.3333333e-02 0.0000000e+00 -2.0000000e+00 -4.0000000e+00 1.6666667e-01 8.3333333e-02 -2.0000000e+00 -3.0000000e+00 8.3333333e-02 3.3333333e-01 -2.0000000e+00 -2.0000000e+00 8.3333333e-02 1.6666667e-01 -2.0000000e+00 -1.0000000e+00 3.3333333e-01 1.6666667e-01 -2.0000000e+00 0.0000000e+00 1.6666667e-01 1.6666667e-01 -2.0000000e+00 1.0000000e+00 4.1666667e-01 3.3333333e-01 -2.0000000e+00 2.0000000e+00 3.3333333e-01 1.6666667e-01 -2.0000000e+00 3.0000000e+00 4.1666667e-01 4.1666667e-01 -2.0000000e+00 4.0000000e+00 8.3333333e-02 4.1666667e-01 -2.0000000e+00 5.0000000e+00 3.3333333e-01 1.0000000e+00 -1.0000000e+00 -5.0000000e+00 1.6666667e-01 1.6666667e-01 -1.0000000e+00 -4.0000000e+00 8.3333333e-02 1.6666667e-01 -1.0000000e+00 -3.0000000e+00 8.3333333e-02 2.5000000e-01 -1.0000000e+00 -2.0000000e+00 2.5000000e-01 8.3333333e-02 -1.0000000e+00 -1.0000000e+00 8.3333333e-02 3.3333333e-01 -1.0000000e+00 0.0000000e+00 3.3333333e-01 3.3333333e-01 -1.0000000e+00 1.0000000e+00 2.5000000e-01 4.1666667e-01 -1.0000000e+00 2.0000000e+00 2.5000000e-01 5.8333333e-01 -1.0000000e+00 3.0000000e+00 5.0000000e-01 1.6666667e-01 -1.0000000e+00 4.0000000e+00 2.5000000e-01 9.1666667e-01 -1.0000000e+00 5.0000000e+00 2.5000000e-01 1.0833333e+00 0.0000000e+00 -5.0000000e+00 8.3333333e-02 0.0000000e+00 0.0000000e+00 -4.0000000e+00 8.3333333e-02 2.5000000e-01 0.0000000e+00 -3.0000000e+00 3.3333333e-01 2.5000000e-01 0.0000000e+00 -2.0000000e+00 1.6666667e-01 1.6666667e-01 0.0000000e+00 -1.0000000e+00 5.8333333e-01 8.3333333e-02 0.0000000e+00 0.0000000e+00 2.5000000e-01 3.3333333e-01 0.0000000e+00 1.0000000e+00 3.3333333e-01 5.8333333e-01 0.0000000e+00 2.0000000e+00 2.5000000e-01 5.8333333e-01 0.0000000e+00 3.0000000e+00 8.3333333e-02 2.5000000e-01 0.0000000e+00 4.0000000e+00 1.0833333e+00 9.1666667e-01 0.0000000e+00 5.0000000e+00 7.5000000e-01 1.2500000e+00 1.0000000e+00 -5.0000000e+00 8.3333333e-02 1.6666667e-01 1.0000000e+00 -4.0000000e+00 8.3333333e-02 2.5000000e-01 1.0000000e+00 -3.0000000e+00 2.5000000e-01 2.5000000e-01 1.0000000e+00 -2.0000000e+00 2.5000000e-01 2.5000000e-01 1.0000000e+00 -1.0000000e+00 3.3333333e-01 1.6666667e-01 1.0000000e+00 0.0000000e+00 5.0000000e-01 6.6666667e-01 1.0000000e+00 1.0000000e+00 3.3333333e-01 4.1666667e-01 1.0000000e+00 2.0000000e+00 2.5000000e-01 1.0833333e+00 1.0000000e+00 3.0000000e+00 5.8333333e-01 9.1666667e-01 1.0000000e+00 4.0000000e+00 2.5000000e-01 1.4166667e+00 1.0000000e+00 5.0000000e+00 9.1666667e-01 9.1666667e-01 2.0000000e+00 -5.0000000e+00 8.3333333e-02 8.3333333e-02 2.0000000e+00 -4.0000000e+00 2.5000000e-01 2.5000000e-01 2.0000000e+00 -3.0000000e+00 2.5000000e-01 2.5000000e-01 2.0000000e+00 -2.0000000e+00 2.5000000e-01 8.3333333e-02 2.0000000e+00 -1.0000000e+00 2.5000000e-01 5.8333333e-01 2.0000000e+00 0.0000000e+00 4.1666667e-01 4.1666667e-01 2.0000000e+00 1.0000000e+00 7.5000000e-01 8.3333333e-01 2.0000000e+00 2.0000000e+00 8.3333333e-01 7.5000000e-01 2.0000000e+00 3.0000000e+00 2.5000000e-01 1.1666667e+00 2.0000000e+00 4.0000000e+00 4.1666667e-01 1.2500000e+00 2.0000000e+00 5.0000000e+00 7.5000000e-01 1.4166667e+00 3.0000000e+00 -5.0000000e+00 3.3333333e-01 1.6666667e-01 3.0000000e+00 -4.0000000e+00 1.6666667e-01 4.1666667e-01 3.0000000e+00 -3.0000000e+00 3.3333333e-01 5.8333333e-01 3.0000000e+00 -2.0000000e+00 1.6666667e-01 4.1666667e-01 3.0000000e+00 -1.0000000e+00 1.6666667e-01 2.5000000e-01 3.0000000e+00 0.0000000e+00 4.1666667e-01 1.0833333e+00 3.0000000e+00 1.0000000e+00 4.1666667e-01 9.1666667e-01 3.0000000e+00 2.0000000e+00 4.1666667e-01 7.5000000e-01 3.0000000e+00 3.0000000e+00 5.0000000e-01 1.2500000e+00 3.0000000e+00 4.0000000e+00 6.6666667e-01 1.0833333e+00 3.0000000e+00 5.0000000e+00 1.4166667e+00 1.2500000e+00 4.0000000e+00 -5.0000000e+00 2.5000000e-01 1.6666667e-01 4.0000000e+00 -4.0000000e+00 2.5000000e-01 2.5000000e-01 4.0000000e+00 -3.0000000e+00 8.3333333e-02 2.5000000e-01 4.0000000e+00 -2.0000000e+00 2.5000000e-01 4.1666667e-01 4.0000000e+00 -1.0000000e+00 2.5000000e-01 8.3333333e-01 4.0000000e+00 0.0000000e+00 2.5000000e-01 9.1666667e-01 4.0000000e+00 1.0000000e+00 4.1666667e-01 4.1666667e-01 4.0000000e+00 2.0000000e+00 4.1666667e-01 1.2500000e+00 4.0000000e+00 3.0000000e+00 2.5000000e-01 1.2500000e+00 4.0000000e+00 4.0000000e+00 9.1666667e-01 1.5833333e+00 4.0000000e+00 5.0000000e+00 1.2500000e+00 1.4166667e+00 5.0000000e+00 -5.0000000e+00 2.5000000e-01 0.0000000e+00 5.0000000e+00 -4.0000000e+00 2.5000000e-01 7.5000000e-01 5.0000000e+00 -3.0000000e+00 3.3333333e-01 8.3333333e-01 5.0000000e+00 -2.0000000e+00 8.3333333e-02 2.5000000e-01 5.0000000e+00 -1.0000000e+00 2.5000000e-01 6.6666667e-01 5.0000000e+00 0.0000000e+00 2.5000000e-01 5.8333333e-01 5.0000000e+00 1.0000000e+00 2.5000000e-01 9.1666667e-01 5.0000000e+00 2.0000000e+00 5.8333333e-01 1.5000000e+00 5.0000000e+00 3.0000000e+00 1.2500000e+00 1.2500000e+00 5.0000000e+00 4.0000000e+00 1.0833333e+00 1.4166667e+00 5.0000000e+00 5.0000000e+00 1.0833333e+00 1.0833333e+00 \end{filecontents} \begin{document} \begin{animateinline}[autoplay, loop, controls, %viewport=0 0 110 153, %scale = 0.9; buttonsize=3ex, buttonfg=1.0:1.0:1.0, buttonbg=0.5]{0.4} % frames por segundo \multiframe{4}{i=1+1}{ \begin{tikzpicture} \begin{axis}[% %3d box, width=0.9\textwidth, height=0.75\textwidth, xmin=-5, xmax=5, xtick={-2.5,0,2.5}, tick align=outside, extra x ticks={-5,5}, extra tick style={ grid=none, }, xlabel={erro TP [\%]}, ymin=-5, ymax=5, ytick={-2.5,0,2.5}, extra y ticks={-5,5}, extra tick style={ grid=none, }, ylabel={erro TC [\%]}, zmin=0, zmax=2, ztick={0,0.5,1,1.5}, extra z ticks={2}, extra tick style={ grid=none, }, zlabel={erro relativo [\%]}, view={-15+360*(\i-1)/4}{47}, grid = major, grid style=dashed ] \addplot3[% surf, draw = black, line width = 0.05pt, %shader= flat corner, colormap name=prop, fill opacity = 0.5, z buffer=auto, unbounded coords=jump, mesh/rows=11] table[x index=0,y index=1,z index=2] {TPTC.dat}; \addlegendentry{proposto} \addplot3[% surf, draw = black, line width = 0.05pt, %shader= flat corner, colormap name=berg, fill opacity = 0.5, z buffer=auto, unbounded coords=jump, mesh/rows=11] table[x index=0,y index=1,z index=3] {TPTC.dat}; \addlegendentry{\textit{Bergeron}} \end{axis} \end{tikzpicture}% } \end{animateinline} \end{document}
- Creating a surface plot of a function on the simplex (using PSTricks or TikZ?)by Martin J. Osborne on March 18, 2017 at 6:46 pm
I'd like to create an exact surface plot of a function defined on the unit simplex {(x, y, z): x + y + z = 1}. Here's a sketch of the figure I'd like to create. I know about surface plots in PSTricks and TikZ, about barycentric coordinate systems in TikZ, and about ternaryaxis in pgfplots, but I don't see a way of combining them to produce what I want. (My difficulty is not with the specific form of the function; I'll be happy with an answer that plots the function x.) I'd like to say something like \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} % or some special type of axis \addplot3 {<f(x,y,z)>}; \end{axis} \end{tikzpicture} \end{document} where f(x,y,z) is the definition of my function. Is something like that possible?
- Draw a 2D functions in tikzby Dipole on August 4, 2015 at 10:58 am
I want to be able to plot in a 3D environment any type of function of two variables z = f(x,y), where x and y are specified within a given range. For instance plot f(x,y) = x^2 + y^2 where x in [-2,2] and y in [-2,2] as a "wireframe" surface plot. I want this plot to go on the rectangle (defined in the same coordinate system) that I have drawn, without the axis labels. How can this be done \documentclass[border=10pt,varwidth]{standalone} \usepackage{tikz,tikz-3dplot} \usepackage{pgfplots} \pgfplotsset{ every axis/.append style = {thick},tick style = {thick,black}, % % #1 = x, y, or z % #2 = the shift value /tikz/normal shift/.code 2 args = {% \pgftransformshift{% \pgfpointscale{#2}{\pgfplotspointouternormalvectorofticklabelaxis{#1}}% }% },% % range3frame/.style = { tick align = outside, scaled ticks = false, enlargelimits = false, ticklabel shift = {10pt}, axis lines* = left, line cap = round, clip = false, xtick style = {normal shift={x}{10pt}}, ytick style = {normal shift={y}{10pt}}, ztick style = {normal shift={z}{10pt}}, x axis line style = {normal shift={x}{10pt}}, y axis line style = {normal shift={y}{10pt}}, z axis line style = {normal shift={z}{10pt}}, } } \begin{document} % ----- First plot \tdplotsetmaincoords{70}{155} \begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick}, vector/.style={-stealth,black,very thick}, vector guide/.style={dotted,black,thick}, ] %standard tikz coordinate definition using x, y, z coords \coordinate (O) at (0,-0.5,0); %tikz-3dplot coordinate definition using r, theta, phi coords \pgfmathsetmacro{\ax}{1} \pgfmathsetmacro{\ay}{-1} \pgfmathsetmacro{\az}{0.5} \coordinate (P) at (\ax,\ay,\az){}; %draw axes \draw[axis] (0,-0.5,0) -- (2,-0.5,0) node[anchor=north east]{$y$}; % x-axis becomes y axis \draw[axis] (0,-0.5,0) -- (0,-2,0) node[anchor=south]{$x$}; %minius y-axis becomes positive x axis \draw[axis] (0,-0.5,0) -- (0,-0.5,2) node[anchor=south]{$z$}; \draw[thick,tdplot_main_coords] (1.5,0.5,0)-- (1.5,-0.5,0) -- (-1.5,-0.5,0)--(-1.5,0.5,0)--cycle; \begin{axis}[range3frame, view={55}{45}] \addplot3[surf, colormap/hot2, samples=41, domain=0:2] {0.1*(x^2+y^2)}; \end{axis} \end{tikzpicture} \end{document}
- How can I map a 3D plot into the planes using pgfplots?by enthu on October 27, 2014 at 12:49 pm
After answering a question in pgfplots, asking to plot a function; I thought about how I can map the 3D function into the planes. Something like the plots in this page but I could not reach any solution. Here are my functions and their output. I want to show the left plot in the xy plane of the 3d plot; or map the function on xz and yz planes. % pdflatex \documentclass[margin=2mm]{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \pgfmathdeclarefunction{F}{3}{\pgfmathparse{#1* exp(#2*#3)}} \begin{axis} [ smooth, grid=both,minor tick num=1, xlabel=$x$,ylabel=$y$, tick align=inside, samples=1000, samples y=0, ] \addplot [solid, thick, data cs=polarrad, domain=0:10*pi] {F(5,-0.1,x)}; \end{axis} \end{tikzpicture} ~ \begin{tikzpicture} \pgfmathdeclarefunction{F}{3}{\pgfmathparse{#1* exp(#2*#3)}} \begin{axis} [smooth, grid=both,minor tick num=1, xlabel=$x$,ylabel=$y$,zlabel=$z$, samples=1000, samples y=0, ] \addplot3+ [solid, thick, black, mark=none, thick, domain=0:10*pi, ] ({F(5,-0.1,x)*cos(deg(x))},{F(5,-0.1,x)*sin(deg(x))},{F(5,-0.1,x)}); \end{axis} \end{tikzpicture} \end{document}
- Flip x and y axis of ternary graphby Raphael on July 18, 2014 at 4:27 am
I am trying to reproduce the USDA Soil Triangle. To do so, I would need to flip the x and y axis of the default pgfplots-ternary. I understand, that I could switch my inputs (don't really want to do that), but I would need to change the directions as well, and I not even having any success with that. In the default ternary axis, the y axis is on the left and the x axis is on the right, and x runs from 0 (bottom right) to 100 (top) and y runs from top to bottom left. However, according to the USDA Soil Triangle, x needs to run from bottom left to top, y needs to run from top to bottom right, and z from bottom right to bottom left. Also, the x axis (and ticks) need to be horizontal (parallel to z), whereas y needs to be parallel to x and z should be parallel to y. I tried the x dir=reverse and axis on top commands, as I thought I could simply flip my coordinates, but I had no luck. Did anybody ever have a similar problem or knows an answer to this? I did what I could to at least have all the data and such. Here is what I got: \documentclass[]{standalone} \usepackage[dvipsnames]{xcolor} % color handling \usepackage{tikz} % draw pictures and diagrams \usepackage{pgfplots} % proper plotting \usepackage{file contents} % writing reading of data files \usepgfplotslibrary{ternary, units} \begin{filecontents*}{USDASoils.csv} name,clay,silt,sand Sand,0,0,100 Sand,10,0,90 Sand,0,15,85 Loamy Sand,0,15,85 Loamy Sand,10,0,90 Loamy Sand,15,0,85 Loamy Sand,0,30,70 Clay,55,0,45 Clay,100,0,0 Clay,60,40,0 Clay,40,40,20 Clay,40,15,45 Sandy Clay,35,0,65 Sandy Clay,55,0,45 Sandy Clay,35,20,45 Silty Clay,40,40,20 Silty Clay,60,40,0 Silty Clay,40,60,0 Loam,8,40,52 Loam,20,27,53 Loam,27,28,45 Loam,27,50,23 Loam,8,50,42 Sandy Loam,0,30,70 Sandy Loam,15,0,85 Sandy Loam,20,0,80 Sandy Loam,20,27,53 Sandy Loam,8,40,52 Sandy Loam,8,50,42 Sandy Loam,0,50,50 Clay Loam,27,28,45 Clay Loam,40,15,45 Clay Loam,40,40,20 Clay Loam,27,53,20 Sandy Clay Loam,20,0,80 Sandy Clay Loam,35,0,65 Sandy Clay Loam,35,20,45 Sandy Clay Loam,27,28,45 Sandy Clay Loam,20,27,53 Silty Loam,0,50,50 Silty Loam,27,50,23 Silty Loam,27,73,0 Silty Loam,13,87,0 Silty Loam,13,80,7 Silty Loam,0,80,20 Silty Clay Loam,27,53,20 Silty Clay Loam,40,40,20 Silty Clay Loam,40,60,0 Silty Clay Loam,27,73,0 Silt,0,80,20 Silt,13,80,7 Silt,13,87,0 Silt,0,100,0 \end{filecontents*} \pgfplotsset{ discard if not/.style 2 args={ x filter/.code={ \edef\tempa{\thisrow{#1}} \edef\tempb{#2} \ifx\tempa\tempb \else \def\pgfmathresult{inf} \fi } } } \begin{document} \begin{tikzpicture}[scale=0.9] \begin{ternaryaxis}[ xmax=100, ymax=100, zmax=100, ternary limits relative, xlabel=x (Clay), ylabel=y (Silt), zlabel=z (Sand), xtick={0,10,...,100}, ytick={0,10,...,100}, ztick={0,10,...,100}, minor tick num=1, grid=both, ] \def\myopacity{0.5} % Sands \addplot3 [fill=yellow, fill opacity=\myopacity, discard if not={name}{Sand}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=Melon, fill opacity=\myopacity,discard if not={name}{Loamy Sand}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; % Sand Text \node at (axis cs:3,5,) {\tiny Sand}; \node at (axis cs:5,13) {\tiny Loamy}; \node at (axis cs:2,18) {\tiny Sand}; % Clays \addplot3 [fill=yellow, fill opacity=\myopacity, discard if not={name}{Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=red, fill opacity=\myopacity, discard if not={name}{Sandy Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=Aquamarine!50, fill opacity=\myopacity, discard if not={name}{Silty Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; %Clay Text \node at (axis cs:65,16) {\tiny Clay}; \node at (axis cs:43,6) {\tiny Sandy}; \node at (axis cs:38,8) {\tiny Clay}; \node at (axis cs:48,47) {\tiny Silty}; \node at (axis cs:44,49) {\tiny Clay}; % Loams \addplot3 [fill=brown, fill opacity=\myopacity, discard if not={name}{Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=purple!50, fill opacity=\myopacity, discard if not={name}{Sandy Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=purple!25, fill opacity=\myopacity, discard if not={name}{Sandy Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=SpringGreen, fill opacity=\myopacity, discard if not={name}{Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=Green, fill opacity=\myopacity, discard if not={name}{Silty Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; \addplot3 [fill=Aquamarine, fill opacity=\myopacity, discard if not={name}{Silty Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; % Loams Text \node at (axis cs:19,40) {\tiny Loam}; \node at (axis cs:12,23) {\tiny Sandy Loam}; \node at (axis cs:28,13) {\tiny Sandy Clay Loam}; \node at (axis cs:33,35) {\tiny Clay Loam}; \node at (axis cs:13,65) {\tiny Silty Loam}; \node at (axis cs:36,55) {\tiny Silty}; \node at (axis cs:31,58) {\tiny Clay Loam}; % Silts \addplot3 [fill=green, fill opacity=\myopacity, discard if not={name}{Silt}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv}; % Silt Text \node at (axis cs:6,88) {\tiny Silt}; \end{ternaryaxis} \end{tikzpicture} \end{document} Which looks like this: I am considerably happy with my result, but I would like to: Switch the axis (as explained above), Remove the minor ticks (but keep the minor grid - I could not get that to work), and have the axis labels sloped along the triangle sides (as in the original picture above)
- plot 3d graphs of functions defined implicitlyby Jay on October 23, 2013 at 2:52 pm
How can I plot 3d graphs of functions defined implicitly (quadratic forms, for Linear Algebra course notes -- I'd like to include lots of examples)? As far as I can see it is not possible with pgfplots and not through gnuplot either. Is there any package that will help with that? For example, parabolic and hyperbolic cylinders, hyperboloids, ellipsoids, etc. Concrete examples: 2xy + 2xz = 1 (hyperbolic cylinder) (x^2)/(2^2) + (y^2)/(3^2) + (z^2)/(2^2) = 1 (ellipsoid) I also see that Maxima can do this: (%11) hc:2*x*y+2*x*z=2; (%i2) draw3d(enhanced3d=true,implicit(hc,x,-5,5,y,-5,5,z,-5,5)); This will work fine (the hyperbolic cylinder is correctly plotted on the screen), but I don't know what backend Maxima uses for this, and I'd like to use a plain LaTeX method, or something that could be called from LaTeX, as I may have to send the document for others to compile themselves on different environments.
- Unwanted Line Drawn Between Ends of Curves in 3Dby Geoff Pointer on October 20, 2013 at 4:57 am
Okay, this was about one of the technical pitfalls and how to avoid it, which was solved quite easily by adding samples y=0 as recommended by Francis. Initial Question The following does two turns of a helix and then joins the start and finish with a straight line for some reason. Plus there's some nasty overlapping happening in the smoothing process. MWE \documentclass{standalone} \usepackage{amsmath} \usepackage{amssymb} \usepackage{pgfplots} \usepackage{mathtools} \pgfplotsset{compat=1.9} \begin{document} % \par\begin{tikzpicture} % \begin{axis}[ scale=3, x={(-0.6cm,-0.3cm)}, y={(.6cm,0.0cm)}, z={(0cm,.2cm)}, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, axis lines=middle, axis on top, xtick={-1,1}, ytick={-1,1},ztick={4,8}, enlargelimits=true ] \addplot3[smooth, thick, color=green, domain=0:720] ({2*sin(x)},{2*cos(x)},{2*x/180}); % \end{axis} % \end{tikzpicture} % \end{document}
- Fill a contour-plotby spookyfw on August 30, 2013 at 12:25 pm
I did some calculations in Mathematica that gave me a contour plot: To include the output I wanted to however draw it with pfgplot. But there I don't get it to work, first of all the y-axis doesn't start at 0 and second I cannot find a specifier to fill the areas between the lines. The part that is white in the plot I am trying to reproduce is an area of complex values that I wanted to exclude as well. My MWE up to now looks like \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat = 1.7} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel = $x$ , ylabel = $y$ , domain = 1:2 , y domain = 0:90 , view = {0}{90} ] \addplot3[ contour gnuplot={number = 30,labels={false}}, thick ]{-2.051^3*1000/(2*3.1415*(2.99*10^2)^2)/(x^2*cos(y)^2)}; \end{axis} \end{tikzpicture} \end{document} with the following output It should be a common problem but I couldn't find a solution. Another thing that I tried was using addplot3 with surf, but the way how the colors are put together didn't seem to work right \addplot3[surf,shader=interp,samples=2, patch type=bilinear]
- Intersection of two surfacesby aagaard on April 23, 2012 at 6:19 am
I'm trying to create a signed distance function S(x), where I want to intersect S(x) = 0 with a plane. The problem is not to get the two functions into a plot, but to get the two functions to visual intersect with each other, i.e the nearest surface is in the foreground. Currently, I have something like: \documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[grid=major] \addplot3[surf,domain=-10:10,samples=40] {-sqrt((x-0)^2/1 + (y-0)^2/1) + 5}; \addplot3[surf,domain=-10:10,samples=2,opacity=0.5] {0*x+0*y}; \end{axis} \end{tikzpicture} \end{document} Which gives: As you can see, the plane is only overlapping the function and not intersecting. How can it be done? Bonus question: Is it possible to create a contour on the 3d surf plot at the intersection?