I saw tomoq’s star-shaped plot on X (Twitter), together with a pretty big implicit function definition:
How to plot this?
An easy way is to consider the left side as a function z=f(x,y) in three dimensions, and that equation would be a contour line at height z=1. So, let’s plot it together with contour lines at different heights, to see how they run.
Run the files with -enable-write18 or –shell-escape or similar option enabled, because contour plots run the external gnuplot program in the background. The won’t run withe the online compiler TeXlive.net here, for security reasons.
% !TEX lualatex \documentclass[border=10pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture}[ declare function = { f(\x,\y) = x^6 + y^6 + 3*x^4*y^2 + 3*x^2*y^4 - 5*x^4*y + 10*x^2*y^3 - y^5; } ] \begin{axis}[ axis lines = middle, domain = -2:2, samples = 80, samples y = 80, enlargelimits ] \addplot3 [ contour lua = { levels = {0.001, 0.1, 1, 4, 8, 16, 32}, labels = false} ] { f(x,y) }; \addplot3 [surf, thick, colormap/violet, opacity = 0.2 ] { f(x,y) }; \end{axis} \end{tikzpicture} \end{document}
To get the final two-dimensional plot, we can choose a viewing angle from above, and plot only the contour line at height level 1.
We can generate this star-shaped plot with pgfplots choosing a contour plot with LuaLaTeX: https://t.co/jglaLYpRSf pic.twitter.com/T5LrV19CP4
— LaTeX.org (@TeXgallery) January 31, 2025
% !TEX lualatex \documentclass[border=10pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture}[ declare function = { f(\x,\y) = x^6 + y^6 + 3*x^4*y^2 + 3*x^2*y^4 - 5*x^4*y + 10*x^2*y^3 - y^5; } ] \begin{axis}[ axis lines = middle, domain = -2:2, samples = 80, samples y = 80, enlargelimits, view = {0}{90} ] \addplot3 [ thick, contour lua = { levels = {1}, labels = false} ] { f(x,y) }; \end{axis} \end{tikzpicture} \end{document}
See also: Original Source by Stefan Kottwitz
Note: The copyright belongs to the blog author and the blog. For the license, please see the linked original source blog.
Leave a Reply
You must be logged in to post a comment.