# Making plots of modular forms¶

Inspired by the images and ideas of Elias Wegert, I thought it might be interesting to attempt to implement a version of his colorizing technique for complex functions in sage. The purpose is ultimately to revisit how one plots modular forms in the LMFDB (see lmfdb.org and click around to see various plots — some are good, others are less good).

The challenge is that plotting a function from $\mathbb{C} \longrightarrow \mathbb{C}$ is that the graph is naturally 4-dimensional, and we are very bad at visualizing 4d things. In fact, we want to use only 2d to visualize it.

A complex number $z = re^{i \theta}$ is determined by the magnitude ($r$) and the argument ($\theta$). Thus

one typical approach to represent the value taken by a function $f$ at a point $z$ is to represent the magnitude of $f(z)$ in terms of the brightness, and to represent the argument in terms of color.

For example, the typical complex space would then look like the following.

```
P = complex_plot(x, [-2, 2], [-2, 2])
P.axes(False)
P.show()
```

To get an idea for a slightly more complicated plot, we might look at $z^2(z-0.5)(z-0.5i)$

```
complicated_func = x**2 * (x - 0.5) * (x - 0.5*i)
```

```
P = complex_plot(complicated_func, [-2, 2], [-2, 2])
P.axes(False)
P.show()
```

Sometimes one chooses to plot only the magnitude or the argument. By discarding the argument, one can use cycling colors to represent changing magnitudes. For example, one could have red represent 0, and as magnitude increases the colors might rotate through purple, blue, green, yellow and orange, and eventually cycle to represent more magnitudes.

```
def normalize(complexval):
return 2*exp(2 * pi * i * complexval.abs())
```

```
f = lambda x: normalize(x)
P = complex_plot(f, [-2, 2], [-2, 2])
P.axes(False)
P.show()
```

Doing this with our slightly more complicated function gives

```
f = lambda x: normalize(complicated_func(x))
P = complex_plot(f, [-2, 2], [-2, 2], plot_points=200)
P.axes(False)
P.show()
```