Plot MultiAxes tutorial/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "===Création de données Plot=== Dans cet exemple, nous allons tracer 3 fonctions, deux, sont celles utilisées dans le Tutoriel de base, et, un po...")
(Created page with "Comme '''x''' passe de '''0''' à '''2''', la fonction '''y''', a une valeur maximale de '''4''', donc, si nous essayons de tracer cette fonction avec des formules trigonomét...")
Line 35: Line 35:
c = [math.cos(math.pi*2.0*tt) for tt in t]
c = [math.cos(math.pi*2.0*tt) for tt in t]
</syntaxhighlight>
</syntaxhighlight>
Comme '''x''' passe de '''0''' à '''2''', la fonction '''y''', a une valeur maximale de '''4''', donc, si nous essayons de tracer cette fonction avec des formules trigonométrique, au moins une fonction sera tronquée, ou mal ajustée, alors nous aurons besoin d'un '''Plot multi-axes'''.
As ''x'' moves from 0 to 2, ''y'' function has a maximum value of 4, so if we try to plot this function with trigonometrical ones, at least one function will be truncated or bad scaled, then we need a multiaxes plot. Multiaxes plot in FreeCAD is oriented to get a plot with multiple axes, not to get multiple plots in same document.


===Drawing functions, adding new axes===
===Drawing functions, adding new axes===

Revision as of 21:16, 5 December 2014

Avant de commencer ce didacticiel, lisez le Tutoriel de base. Dans ce tutoriel, vous apprendrez comment créer, et, modifier un tracé multi-axes.

Ici, vous en apprendrez plus sur le module Plot.

exemple Multiaxes Plot
exemple Multiaxes Plot
exemple Plot Multiaxes.

Dans l'image précédente, vous pouvez avoir une idée du résultat que l'on peut obtenir.

Dans ce tutoriel, vous apprendrez :

  • Comment créer un multiaxes Plot à partir de la Console Python.
  • Comment faire pour modifier les propriétés des axes.
  • Comment contrôler la grille/légende, lorsque plusieurs axes sont présent.
  • Comment faire pour modifier des étiquettes (labels), des titres, et, des positions des légendes.

Traceur de données

Comme nous l'avons fait dans le tutoriel, nous utiliserons la console Python intégrée, ou des macros, afin de tracer les données, avec la différence, que dans ce cas nous tracerons les données dans deux axes différents.

Création de données Plot

Dans cet exemple, nous allons tracer 3 fonctions, deux, sont celles utilisées dans le Tutoriel de base, et, un polynôme.

Le problème est que, un polynôme, aura besoin de nouveaux axes, la raison est, la variation de la gamme, qui est différente de toutes les autres.

Les commandes suivantes, vont nous créer des tableaux de données :

 import math
 p = range(0,1001)
 x = [2.0*xx/1000.0 for xx in p]
 y = [xx**2.0 for xx in x]
 t = [tt/1000.0 for tt in p]
 s = [math.sin(math.pi*2.0*tt) for tt in t]
 c = [math.cos(math.pi*2.0*tt) for tt in t]

Comme x passe de 0 à 2, la fonction y, a une valeur maximale de 4, donc, si nous essayons de tracer cette fonction avec des formules trigonométrique, au moins une fonction sera tronquée, ou mal ajustée, alors nous aurons besoin d'un Plot multi-axes.

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

 import Plot
 Plot.plot(x,y,r"$x^2$")

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.

 Plot.addNewAxes()
 Plot.plot(t,s,r"$\sin\left( 2 \pi t \right)$")
 Plot.plot(t,c,r"$\cos\left( 2 \pi t \right)$")

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 plot

Configuring axes

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

Axes configuration tool icon
Axes configuration tool icon
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:

  • Title = Multiaxes example
  • X Label = $x$
  • Y Label = $\mathrm{f} \left( x \right)$

Axes 1:

  • 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
Position editor icon
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.