Plot MultiAxes tutorial/es

Antes de comenzar con el presente tutorial aseguresé de haber completado el tutorial sobre graficado básico. En este tutorial aprenderemos a crear y trabajar con gráficos con múltiples ejes de referencia. Puedes aprender más sobre el Módulo de graficado aquí.

Ejemplo de gráfico con múltiples ejes.

En la imagen anterior tenemos una muestra del aspecto del gráfico que pretendemos trazar. Siguiendo este tutorial usted aprenderá:


 * A crear gráficos con múltiples ejes desde la consola de Python.
 * A editar los diferentes juegos de ejes..
 * A controlar la legenda y la malla cuando existen varios juegos de ejes.
 * A reposicionar títulos y legenda.

Graficar
Tal y como hicimos en el anterior tutorial, vamos a emplear la consola de Python, o en su defecto las macros, para graficar los datos, con la diferencia de que en este caso lo haremos con varios juegos de ejes.

Crear los datos
En este ejemplo trazaremos tres curvas, dos de ellas serán las empleadas en el tutorial anterior, pero añadiremos una más de tipo polinómico. El objetivo es que los rangos de variación de esta función sean diferentes a los de las funciones polinómicas. Para crear todos los vectores de datos necesarios ejecutamos los siguientes comandos: Al moverse x entre 0 y 2, y se moverá entre 0 y 4, luego si trataramos de graficar esta función junto con las funciones trigonométricas, que se mueven entre 0 y 1, al menos una de las funciones estará o bien truncada, o bien mal escalada, y por tanto estamos interesados en emplear un segundo juego de ejes. Los gráficos con múltiples ejes en FreeCAD están orientados a la producción de gráficos con diferentes juegos de ejes de referencia, pero no para la creación de documentos con múltiples gráficos.

Drawing functions, adding new axes
We will draw polynomial function at main axes. If all your axes will have same size then is not relevant what function is ploted in what axes, but if your plot has axes with other size (as in this example), main axes must be the biggest one (because this axes have the white background). In order to do it we only need to launch a command In this example we pass directly the series label for the legend. Note that the label string has the r prefix in order to avoid Python try to interpret special characters (\ symbol is used frecuently in LaTeX syntax).

Now we can plot trigonometrical functions, creating new axes before. In FreeCAD Plot module when you create new axes this axes are selected as active ones, so new plots will be associated to this axes. As you can see you plot has gone crazy, with axes ticks overlaped, curves of same color, etc. Now we needs to use FreeCAD Plot module to fix this graph.

Configuring axes
FreeCAD Plot module provides a tool in order to modify the properties of each axes.

Axes configuration tool icon.

The first thing that you can find in axes tool is the active axes selector. Since the active axes are the last one, active axes is placed at one. The axes tool, as labels tool, allows to set the active axes, allowing you to plot more data in the axes that you want (including add/remove axes). For the moment we will work over the selected axes, that are the associated to trigonometrical functions.

In the dimensions sliders, we will move left horizontal and bottom vertical sliders (try to emulate example) in order to reduce axes size. Then we can set the axes alignement, changing it to top and right, and setting and small offset of two units.

Configuring series
Set series properties as we did in previous tutorial.

Showing grid and legend
Grid and legend is shown and hide with the same tools that used in previous tutorial, but in this case the behaviour is a little bit different due to the presence of two different axes.

Regarding grid lines, you can show lines for each axes set, for example, if you try to show grid now you will show only the grid of the trigonometrical functions, so in order to show the grid of polynomial function plot you needs to change active axes to 0 (using axes configuration tool) before using grid tool another time (Is possible that you need to press two times the tool).

Regarding legend, the legend will be the same for both axes, so you can choose the axes that you want in order to show the legend, but is strongly recommended to use the biggest ones (0 in this example) because position will be refered to this axes coordinates. If you show the legend you can see that is really bad placed, we will fix this problem later.

Setting axes labels
You can set axes labels with same tool used in previous tutorial, with the difference that now you have more axes. Since axes labels is ussually set as one per axis, is not a significant difference, but FreeCAD Plot module allow you to set a title by axes too. In this case we only wants to set title to main axes, so set:

Axes 0: Axes 1:
 * Title = Multiaxes example
 * X Label = $x$
 * Y Label = $\mathrm{f} \left( x \right)$
 * X Label = $t$
 * Y Label = $\mathrm{f} \left( t \right)$

Set also 20 to fontsize for all but title, that uses a fontsize of 24. As happens with legend, title is bad placed, interseting with second axes set, so we need to solve both problems.

Setting elements position
FreeCAD Plot module provides a tool in order to set the position of several plot elements, as titles, labels or legend.

Position editor icon.

When you run the tool you see a list with all the editable elements. Title elements, as well as legend, can be moved in both directions, since axes labels can be moved only on the axes direction. Select title of axes 0 and move it to (0.24,1.01), then select legend and move it to a better position. You can increase legend labels fontsize too.

Saving plot
Now you can save your work. See previous tutorial if you don't remeber how to do it.