Plot MultiAxes tutorial/fr: Difference between revisions

From FreeCAD Documentation
m (minor)
(Updating to match new version of source page)
Line 1: Line 1:
Ensure to visit [[Plot_Basic_tutorial|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 [[Plot_Module|Plot module here]].
=Plot_MultiAxes_tutorial/fr=
__TOC__


[[Image:Plot_MultiAxes_Example.png|600px|center|Multiaxes plot example]]
Avant de commencer ce didacticiel, lisez le [[Plot_Basic_tutorial/fr|Tutoriel de base]]. Dans ce tutoriel, vous apprendrez comment créer, et, modifier un tracé '''multi-axes'''.
<center><span style="font-variant:small-caps">Multiaxes plot example.</span></center>


In previous image you can see the result that we aproximately will obtain. Following this tutorial you will learn:
Ici, vous en apprendrez plus sur le '''[[Plot_Module/fr|module Plot]]'''.
* How to create a multiaxes Plot from Python Console.
* How to edit axes properties.
* How to control grid/legend when several axes is present.
* How to edit labels, titles and legend positions.


==Plotting data==
[[Image:Plot_MultiAxes_Example.png|480px|center|exemple Multiaxes Plot]]
As we did in [[Plot_Basic_tutorial|previous tutorial]] we will use the Python console or [[Macros|macros]] in order to plot the data, with the difference that in this case we will plot the data in two different axes.
<center><span style="font-variant:small-caps">exemple Plot Multiaxes.</span></center>

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 [[Plot_Basic_tutorial/fr|tutoriel]], nous utiliserons la console Python intégrée, ou des [[Macros/fr|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 [[Plot_Basic_tutorial/fr|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 :


===Creating plot data===
In this example we will plot 3 functions, the two ones used in [[Plot_Basic_tutorial|previous tutorial]], and another polynomial one. The fact is that the polynomial one will need new axes due to the variation range is different from all others. Next commands will create data arrays for us:
<syntaxhighlight>
import math
import math
p = range(0,1001)
p = range(0,1001)
Line 37: Line 23:
s = [math.sin(math.pi*2.0*tt) for tt in t]
s = [math.sin(math.pi*2.0*tt) for tt in t]
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>
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===
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'''.
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

<syntaxhighlight>
La fonction '''Plot multi-axes''' de FreeCAD, est orienté de manière à obtenir un '''Plot''' à axes multiples, pour ne pas obtenir de multiples combinaisons dans le même document.

===Fonction ajoutant de nouveaux axes de dessin===

Nous allons exécuter une fonction polynomiale à axes principaux. Si tous vos axes ont la même taille alors, il n'est pas pertinent que la fonction soit mesurées dans les axes, mais il faut que votre '''Plot''' aie des axes de dimensions différentes (comme dans cet exemple), les axes principaux doivent être plus grand (car ces axes ont un fond blanc).

Pour ce faire, il suffit de lancer une commande :

import Plot
import Plot
Plot.plot(x,y,r"$x^2$")
Plot.plot(x,y,r"$x^2$")
</syntaxhighlight>
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 [http://www.latex-project.org LaTeX] syntax).


Now we can plot trigonometrical functions, creating new axes before. In [[Plot_Module|FreeCAD Plot module]] when you create new axes this axes are selected as active ones, so new plots will be associated to this axes.
Dans cet exemple, nous transmettons directement l'étiquette (label) de la série pour la légende. Notez que la chaîne d'étiquettes, a le préfixe '''r''', afin d'éviter que Python ne tente d'interpréter les caractères spéciaux (symbole '''\''' qui est fréquemment utilisé dans la syntaxe [http://www.latex-project.org LaTeX]).
<syntaxhighlight>

Maintenant nous pouvons tracer des fonctions trigonométriques, mais avant, créez de nouveaux axes. Dans '''[[Plot_Module/fr|FreeCAD Plot module]]''' lorsque vous créez de nouveaux axes, ces axes sont sélectionnés comme actifs, donc, de nouveaux '''Plots''', seront associés à ces axes.

Plot.addNewAxes()
Plot.addNewAxes()
Plot.plot(t,s,r"$\sin\left( 2 \pi t \right)$")
Plot.plot(t,s,r"$\sin\left( 2 \pi t \right)$")
Plot.plot(t,c,r"$\cos\left( 2 \pi t \right)$")
Plot.plot(t,c,r"$\cos\left( 2 \pi t \right)$")
</syntaxhighlight>
As you can see you plot has gone crazy, with axes ticks overlaped, curves of same color, etc. Now we needs to use [[Plot_Module|FreeCAD Plot module]] to fix this graph.


==Configuring plot==
Comme vous pouvez le voir '''Plot''' est devenu fou, avec axes qui pointes, et, qui s'empiètent, courbes de même couleur, etc.. .


===Configuring axes===
Maintenant nous avons besoin d'utiliser '''[[Plot_Module/fr|FreeCAD Plot module]]''', avec la complexité de ce graphique.
[[Plot_Module|FreeCAD Plot module]] provides a tool in order to modify the properties of each axes.

==Configurer Plot==

===Configurer les axes===

La fonction [[Plot_Module/fr|FreeCAD Plot module]] fournit un outil, pour modifier les propriétés de chacun des axes.


[[Image:Plot_Axes.png‎|center|Axes configuration tool icon]]
[[Image:Plot_Axes.png‎|center|Axes configuration tool icon]]
<center><span style="font-variant:small-caps">Axes configuration tool icon.</span></center>
<center><span style="font-variant:small-caps">Axes configuration tool icon.</span></center>


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.
La première chose que vous trouverez dans l'outil, {{KEY|[[Image:Plot_Axes.png|16px|text-top=Ajouter, effacer ou éditer les axes Plot|link=Plot_Axes/fr]] [[Plot_Axes/fr|Plot_Axes]]}}, est le sélecteur d'axes actif.
Pour l'instant, nous allons travailler sur l'ensemble des axes 1, la dernière chose que nous générons


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.
Puisque les axes actifs sont les derniers, les axes actifs sont placés en premier.


===Configuring series===
L'outil axes, comme l'outil {{KEY|[[Image:Plot_Labels.png|16px|text-top=Éditer les labels|link=Plot_Labels/fr]] [[Plot_Labels/fr|Plot_Labels]]}}, permettent de définir les axes actifs, et, permettent de tracer plus de données dans l'axe que vous souhaitez (y compris ajouter/supprimer des axes). Pour l'instant, nous allons travailler sur les axes sélectionnés, et, qui sont associés aux fonctions trigonométriques.
Set series properties as we did in [[Plot_Basic_tutorial|previous tutorial]].


===Showing grid and legend===
Utilisez les ascenseurs pour modifier les réglages, déplaçons le curseur gauche pour les réglages '''horizontaux''', et, le curseur du bas pour les réglages '''verticaux''' (essayez d'imiter l'exemple) afin de réduire la taille des axes.
Grid and legend is shown and hide with the same tools that used in [[Plot_Basic_tutorial|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).
Nous pouvons alors définir l'alignement des axes, et, changer en haut, et, à droite, en définissant un petit décalage de deux unités.


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.
===Configurer les Series===


===Setting axes labels===
Pour définir les propriétés des {{KEY|[[Image:Plot_Series.png|16px|text-top=Éditer les séries titres et style|link=Plot_Series/fr]] [[Plot_Series/fr|Plot_Series]]}} que nous avons fait, regardez dans [[Plot_Basic_tutorial/fr|Tutoriel]].
You can set axes labels with same tool used in [[Plot_Basic_tutorial|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 [[Plot_Module|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:

===Afficher la grille et les légendes===

Les {{KEY|[[Image:Plot_Grid.png|16px|text-top=Afficher/Cacher la grille|link=Plot_Grid/fr]] [[Plot_Grid/fr|Plot_Grid (grilles)]]}}, et, les {{KEY|[[Image:Plot_Legend.png|16px|text-top=Afficher/Cacher les légendes|link=Plot_Legend/fr]] [[Plot_Legend/fr|Plot_Legend (légendes)]]}} apparaissent cachées avec les mêmes outils utilisés dans le [[Plot_Basic_tutorial/fr|tutoriel]], mais dans ce cas, le comportement est un peu différent, en raison de la présence de '''deux axes différents'''.

Concernant les lignes de la grille, vous pouvez, afficher les lignes pour chaque ensemble d'axes, par exemple, si vous essayez d'afficher une grille maintenant vous montrerez uniquement la grille des fonctions trigonométriques, donc afin de montrer la grille du tracé de la fonction polynôme, vous avez besoin de mettre les axes actifs à '''0''' (en utilisant l'outil de configuration des {{KEY|[[Image:Plot_Axes.png|16px|text-top=Ajouter, effacer ou éditer les axes Plot|link=Plot_Axes/fr]] [[Plot_Axes/fr|Plot_Axes]]}}), pour utiliser l'outil {{KEY|[[Image:Plot_Grid.png|16px|text-top=Afficher/Cacher la grille|link=Plot_Grid/fr]] [[Plot_Grid/fr|Plot_Grid]]}} une autre fois (il faut appuyer une deuxième fois sur l'outil).

Au sujet de la {{KEY|[[Image:Plot_Legend.png|16px|text-top=Afficher/Cacher les légendes|link=Plot_Legend/fr]] [[Plot_Legend/fr|légende (Plot_Legend)]]}}, la légende sera la même pour les deux axes, vous pouvez donc choisir les axes que vous souhaitez, afin d'afficher la {{KEY|[[Image:Plot_Legend.png|16px|text-top=Afficher/Cacher les légendes|link=Plot_Legend/fr]] [[Plot_Legend/fr|légende (Plot_Legend)]]}}, mais il est fortement recommandé, d'utiliser les plus grands (0 dans cet exemple), parce que la position sera référée, à cet axe de coordonnées.

Il est possible que vous affichiez une légende, et, que cette légende soit très mal placée, patientez un peu, ce problème sera résolu plus tard.

===Définition des étiquettes axiales===

Vous pouvez définir des étiquettes, et, des axes avec le même outil, utilisé dans [[Plot_Basic_tutorial/fr|previous Tutoriel]], à la différence près, que maintenant vous avez plus d'axes.

Les étiquettes utilisées sur les axes, sont habituellement, une par axe, il n'y a pas de différence significative, mais le [[Plot_Module/fr|Module Plot de FreeCAD]] permet de définir un titre en plus par axe.

Dans cet exemple nous ne ne mettons un titre, qu'aux axes principaux, alors la valeur :


'''Axes 0:'''
'''Axes 0:'''
Line 113: Line 75:
* Y Label = $\mathrm{f} \left( t \right)$
* 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.
La valeur de la police est '''20''' pour tous, sauf le titre, qui utilise une valeur de police de '''24'''.


===Setting elements position===
Que se passe-t-il avec la légende, et, le titre mal placé, intersection avec le deuxième ensemble d'axes, donc nous devons résoudre ces deux problèmes.
[[Plot_Module|FreeCAD Plot module]] provides a tool in order to set the position of several plot elements, as titles, labels or legend.

===Définition de la position des éléments===

[[Plot_Module/fr|FreeCAD Plot module]] fournit un outil pour définir la position de plusieurs éléments, comme, les {{KEY|[[Image:Plot_Series.png|16px|text-top=Éditer les séries titres et style|link=Plot_Series/fr]] [[Plot_Series/fr|titres (Series)]]}}, les {{KEY|[[Image:Plot_Labels.png|16px|text-top=Éditer les labels|link=Plot_Labels/fr]] [[Plot_Labels/fr|labels]]}}, ou la {{KEY|[[Image:Plot_Legend.png|16px|text-top=Afficher/Cacher les légendes|link=Plot_Legend/fr]] [[Plot_Legend/fr|légende]]}}.


[[Image:Plot_Positions.png‎|center|Position editor icon]]
[[Image:Plot_Positions.png‎|center|Position editor icon]]
<center><span style="font-variant:small-caps">Position editor icon.</span></center>
<center><span style="font-variant:small-caps">Position editor icon.</span></center>


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.
Lorsque vous exécutez l'outil, vous voyez une liste, avec tous les éléments modifiables.

Les éléments de titres, ainsi que les légendes, peuvent être déplacés dans les deux sens, les étiquettes des axes, ne peuvent être déplacées uniquement sur l'orientation des axes.

Sélectionnez le titre des axes '''0''', et, déplacez-le vers ('''0.24,1.01'''), puis sélectionnez la légende, et, déplacez-le dans une meilleure position. Vous pouvez augmenter la dimension de la police.

==Sauver Plot==


==Saving plot==
Vous pouvez sauver votre travail avec {{KEY|[[Image:Plot_Save.png|16px|text-top=Sauver|link=Plot_Save/fr]] [[Plot_Save/fr|Plot_Save]]}}. Ou allez voir dans le [[Plot_Basic_tutorial/fr|tutorial]], comment faire, si vous l'avez oublier.
Now you can save your work. See [[Plot_Basic_tutorial|previous tutorial]] if you don't remeber how to do it.


[[Category:Tutorials]]
{{LesOutilsPlot}}


[[Category:Tutorials/fr]]


{{clear}}
{{languages/fr | {{en|Plot_MultiAxes_tutorial}} {{es|Plot_MultiAxes_tutorial/es}} {{it|Plot_MultiAxes_tutorial/it}} }}
<languages/>

Revision as of 20:54, 5 December 2014

Ensure to visit 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 Plot module here.

Multiaxes plot example
Multiaxes plot example
Multiaxes plot example.

In previous image you can see the result that we aproximately will obtain. Following this tutorial you will learn:

  • How to create a multiaxes Plot from Python Console.
  • How to edit axes properties.
  • How to control grid/legend when several axes is present.
  • How to edit labels, titles and legend positions.

Plotting data

As we did in previous tutorial we will use the Python console or macros in order to plot the data, with the difference that in this case we will plot the data in two different axes.

Creating plot data

In this example we will plot 3 functions, the two ones used in previous tutorial, and another polynomial one. The fact is that the polynomial one will need new axes due to the variation range is different from all others. Next commands will create data arrays for us:

 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]

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

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.