Plot MultiAxes tutorial

Please complete the basic tutorial before starting with this tutorial. In this tutorial we will learn how to create and edit a multiaxes plot. You can learn more about the Plot module here.



In the previous image you can see the result that we will aproximately obtain. Following this tutorial you will learn:
 * How to create a multiaxes Plot from the Python console.
 * How to edit axes properties.
 * How to control grid/legend when several axes are present.
 * How to edit labels, titles and legend positions.

Plotting data
As we did in the previous tutorial we will use the Python console or macros to plot the data, but in this case we will plot the data using two different axes.

Creating plot data
In this example we will plot 3 functions, the two used in the previous tutorial, and a new polynomial one. The range of the polynomial function is different from the other functions therefore new axes are required. The next commands will create the data arrays for us:

As x moves from 0 to 2, the y function has a maximum value of 4, so if we try to plot this function with the trigonometrical ones, at least one function will be truncated or bad scaled, therefore we we need a multiaxes plot. A multiaxes plot in FreeCAD is intended to get a plot with multiple axes, not to get multiple plots in the same document.

Drawing functions, adding new axes
We will plot the polynomial function using the main axes. If all your axes have the same size it is not relevant which function is plotted first, but if this is not the case the function that uses the main, the biggest, axes must be plotted first (to ensure they are plotted on the white background). In order to do this we only need to launch a command.

In this example we pass the series label for the legend directly. Note that the label string has the r prefix in order to prevent Python from trying to interpret special characters (the \ symbol is used frequently in LaTeX syntax).

Before we can plot the trigonometrical functions, we need to create new axes. In the Plot module new axes are automatically selected as the active ones, and new plots will be associated with these axes.

As you can see your plot has gone crazy, with axes ticks overlapping, curves of the same color, etc. Now we need to use the Plot module to fix this graph.

Configuring axes
Plot module provides a tool to modify the properties of axes.



With the axes tool you can add or remove axes, and set the active axes, which are then used if you to plot more data. For the moment we will work with the selected axes, the last axes, which are associated with the trigonometrical functions.

We will move the horizontal and vertical dimension sliders to reduce the size of the axes (try to emulate example). Then we can set the axes alignment, changing it to top and right, and apply a small offset of two units.

Configuring series
Set the series properties as we did in the 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.



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 remember how to do it.