Mathematical plots in LaTeX with symbolic expressions

less than 1 minute read

Pretty ofted I need to include mathematical plots in my LaTeX documents. Using an external tools such as R to generate the plot and then including it to the documents is unconfortable and leads to many maintenance problems. Fortunetly, LaTeX provides several ways to overcome this problem.

A very convenient method to mathematical plotting from LaTeX from Tikz. An example follows.

In the example x and y labels are set as LaTeX expressions, so it is straightforward to show complex mathematical expressions. The formula that is actually depicted is another expression used with the command \addplot. The previous code generates the following plot.

Customizing the output is quite easy, as the next example shows.

The LaTeX/Tikz code that generates the previous plot is:

In this case the function deg transforms radians to degrees, the x domain is restricted to [-2, 4], two plots are overlapped with different colors and the plot includes a leyend.

Updated: