You can find a Python script for plotting tropical curves defined by a tropical polynomial here. The same script, but as a .exe file can be found here.
The script also plots the dual subdivision and can plot the tikz code for the figures.
It uses the packages numpy, matplotlib and tkinter.
If you are on Windows, you can just download the exe-version and are ready to go.
Short notes on how to use the program:
Starting the program will open a window where you can input a polynomial and change several options and an empty second window where the optional printed output will appear.
Input of the polynomial: For a term "\( a\odot x^iy^j\oplus b\odot x^ky^l\)" the input has to be "axiyj+bxkyl". So for example the minimal input for
"\(0\oplus 2\odot x^{1}y^{1}\oplus 0\odot x^{2}\oplus (-0.1)\odot x^{2}y^{1}\)" is "x2+2xy-0.1x2y+0".
Hitting the plot button will generate two figures, one of the curve, one of its dual subdivision and print all the things you specified in the options.
For more details on how to make this script work, what the options do, which inputs are allowed and how to configure default values, see here.
Plotting tropical hypersurfaces in three dimensions
You can find a Python script for plotting tropical hypersurfaces in \(\mathbb{R}^3\) here. An even easier-to-use program written
by Lars Allermann can be found here.
My script, however, does plot the edges of the dual subdivision, too. There is no support for min-convention yet and you have to do the input directly in the file. Running it will immediately show you the plots.
This script uses the packages numpy, matplotlib and scipy.
For more details on how to make this script work and how the input works, see here.
Disclaimer
Use all the scripts on this website at your own risk. I am confident that they work very well for reasonable input, however, I do not guarantee that all outputs are correct.
If you find any bugs, please contact me.
I only learned Python to write these scripts, so don't be surprised if my codes might not be the most elegant or efficient ones ever written.
On plotting tropical curves
How to install Python and necessary packages
I use Windows, so here is how it worked for me: Download Python from the official website. Install it - AND make sure that you
pick the "Add Python to PATH" during the installation.
Download pip with the command "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py" in the command prompt (You find that by pressing the Windows key and then typing cmd. The "" are not part of the command).
Install pip with the command "python get-pip.py". Use the commands "pip install numpy", "pip install matplotlib" to install the two packages. "math", "re" and "tkinter" are pre-installed.
If you use Linux or macOS: Ask chatGPT how to install everything. You might need to install "tkinter" explicitly, too.
The options
If you tick "use max-convention", the polynomial will be interpreted as a tropical polynomial
where "+" means max. Else "+" will mean min.
x-range and y-range define the plotting range
Color of curve/dual subdivision/Newton polygon: Changes the color of the curve/dual subdivision/Newton polygon, also in the tikz code
If you tick "Draw a grid", the plot will show a grid. This does not affect the tikz code
If you tick "Print ends of edges", the coordinates of the vertices of the curve and of its intersection points with the boundary of the plotting range will get printed.
If you tick "Show weights of edges", the weights bigger than 1 will occur both in the plot and in the tikz code
The options "Size of weights" and "Color of weights" change size and color of the weights both in the plot and in the tikz code
The last two options decide whether the tikz code for the curve, resp. its dual, will get printed. If you print the code for the curve, you will also get the LaTeX code of the tropical polynomial.
Input
Some remarks about the input
In the input for the polynomial, blanks, "^", "*", parenthesis "(" and ")" will be ignored and "+-" will be handled like a "-". "+" and "-" always seperate monomials. For a monomial with no coefficient,
the coefficient is assumed to be 0. "3x2y" and "3yx2" are interpreted as the same term. Coefficients of monomials will be added if possible, i.e. "3xy + 4yx" gets simplified to "4xy" if max-convention is active, else to "3xy".
Coefficients of the polynomial and the values for the x- and y-range should differ by more than 0.00000000000001. This is because two numbers are considered equal if they differ by less than 0.00000000000001.
The allowed colors are all colors allowed in matplotlib. However, the same color gets used for the tikz code, so if you use
this option, make sure that it is also a tikz-color. Colors that work for both are for example: blue, black, red, green, cyan, magenta, yellow, orange, purple, pink, brown, gray, lime, olive, violet and teal
Change default values
If you open the file in your favorite editor, you will immediately see a comment that reads "#Default values". Change the variables
underneath to the values to the default values you want.
The algorithm
The idea is the following:
Go through all triples of monomials and solve for the point where they are equal and maximal. Store the point and which monomials were maximal.
For the edges of the plotting range, do the same for pairs of monomials
Go through all pairs of saved points and check whether the middle point is part of the curve. If it is, and the max is attained by the right monomials, connect the two points and remember the exponents for the dual
Why I wrote this script
There are already existing programs to plot tropical curves. And they are probably faster, more elegant, and use only algebraic methods.
My motivations for writing this script were mostly the following two: Writing it was fun and it is easy to use. This is also why I tried to keep all explanations very low level.
On plotting tropical hypersurfaces in three dimensions
How to install Python and necessary packages
I use Windows, so here is how it worked for me: Download Python from the official website.
Install it - and make sure that you pick the "Add Python to PATH" during the installation.
Download pip with the command "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py" in the command prompt (You find that by pressing the Windows key and then typing cmd. The "" are not part of the command).
Install pip with the command "python get-pip.py". Use the commands "pip install numpy", "pip install matplotlib", "pip install scipy" to install the three packages. "math", "re" and "tkinter" are pre-installed.
If you use Linux or macOS: Ask chatGPT how to install everything. You might need to install "tkinter" explicitly, too.
Input
For this script, you have to manually adjust the input in the code. If you open the file, after line 15 (''' INPUT ''') there are more explanations on how to do this.
The algorithm
The idea, similarly to the two-dimensional case, is:
Solve for the points where four monomials are equal and maximal, remember the monomials too.
Solve for the points on the boundary of the plot where three monomials are equal and maximal, remember the monomials too.
Check which of these points to connect.
Solve for the points on the edges of the plotting range where two monomials are equal and maximal, remember the monomials.
Go through all possible pairs of monomials and check which of the computed points contain them in their maximal monomials.
Plot the polygons defined by these points, compute the edges of the dual from the exponents of the monomials.
Obviously, there are quite a few details I skipped here.
Why I wrote this script
There are already existing programs to plot tropical hypersurfaces. And they are probably faster, more elegant, and use only algebraic methods.
My motivations for writing this script were mostly the following two: Writing it was fun and it is easy to use (This is also why I tried to keep all explanations very low level.).
At the time I didn't know the program by Lars Allermann. Still, plotting the dual is an advantage my script has.
How to get a website like this
Website Hosting
This website is hosted on GitHub. Here is a good reference on how to start your own website. Thanks to Thomas Brazelton for this hint!
Writing the HTML code
Here is the obvious hint: Describe to chatGPT how you want your website to look and the structure to be and ask it to give you the HTML code. This works incredibly well.