Plot MultiAxes tutorial/it: Difference between revisions

From FreeCAD Documentation
(languages/fr, PlotTools/it)
(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]].
=Guida al Grafico multiasse=


[[Image:Plot_MultiAxes_Example.png|600px|center|Multiaxes plot example]]
{{TOCright}}
<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:
Prima di seguire questo tutorial è bene leggere la [[Plot_Basic_tutorial/it|guida di base sui Grafici]].<br>In questo tutorial si descrive come creare e modificare un '''Grafico MultiAsse'''.<br> Consultare anche la sezione [[Plot_Module/it|Modulo Grafico]].
* 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|600px|center|Esempio di grafico multiasse]]
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">Esempio di grafico multiasse.</span></center>

Nell'immagine precedente si può vedere il risultato finale approssimativo di questa esercitazione. In questo tutorial si descrive come:

* Creare un grafico MultiAsse dalla console Python.
* Modificare le proprietà degli assi.
* Controllare la griglia e la legenda quando sono presenti più sistemi di assi.
* Riposizionare le etichette, i titoli e le legende.

==Creare il grafico==

Come descritto nella [[Plot_Basic_tutorial/it|guida di base]], si usa la console Python o le macro per tracciare i dati, con la differenza che in questo caso i dati sono tracciati in due diversi sistemi di assi.

===Creare i dati===

In questo esempio, vengono tracciate 3 funzioni: le due utilizzate nel [[Plot_Basic_tutorial/it|precedente tutorial]], e una nuova funzione polinomiale. Il polinomio ha bisogno di un nuovo sistema di assi in quanto il suo campo di variazione è diverso da tutti gli altri.<br> I seguenti comandi creano i gruppi di dati necessari:


===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 30: 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===
Dato che x varia tra 0 e 2, la funzione y varia tra 0 e 4, quindi provando a tracciare questa funzione con quelle trigonometriche, che variano invece tra 0 e 1, almeno una funzione verrà troncata o scalata male, perciò serve un grafico MultiAsse.<br>In FreeCAD il grafico Multiasse è destinato a produrre un grafico con più assi, e non per produrre più grafici nello stesso documento.
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>
===Tracciare le funzioni, aggiungere nuovi assi===

In questo esempio la funzione polinomiale viene tracciata nel sistema di assi principali. Se tutti gli assi hanno stesse dimensioni non è rilevante in quali assi viene tracciata una funzione, ma se il grafico ha assi con dimensioni diverse, come in questo caso, gli assi principali devono essere quelli più grandi (perché hanno lo sfondo bianco).<br>Per tracciare la prima curva basta lanciare i seguenti comandi:

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.
Questa volta si passa anche direttamente l'etichetta della serie per la legenda. Notare che la stringa passata come argomento etichetta ha il prefisso '''r''' per evitare che Python tenti di interpretare i caratteri speciali (il simbolo '''\''' è usato di frequente nella sintassi [http://www.latex-project.org LaTeX]).
<syntaxhighlight>

Per tracciare le funzioni trigonometriche è necessario creare prima dei nuovi assi.<br>Nel modulo [[Plot_Module/it|Grafico]] di FreeCAD quando si creano dei nuovi assi essi sono selezionati come quelli attivi, e pertanto i nuovi tracciati sono associati a questi nuovi assi.

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==
Come si può vedere il grafico ha un pessimo aspetto, con le tacche degli assi sovrapposte, le curve dello stesso colore, ecc. Per risolvere questi problemi ora si passa a usare il modulo [[Plot_Module/it|Grafico]] di FreeCAD.


===Configuring axes===
==Configurare il grafico==
[[Plot_Module|FreeCAD Plot module]] provides a tool in order to modify the properties of each axes.


[[Image:Plot_Axes.png‎|center|Axes configuration tool icon]]
===Configurare gli assi===
<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.
Il modulo [[Plot_Module/it|Grafico]] di FreeCAD fornisce uno strumento per modificare le proprietà di ogni asse.


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.
[[Image:Plot_Axes.png‎|center|Icona dello strumento di configurazione degli assi.]]
<center><span style="font-variant:small-caps">Icona dello strumento di configurazione degli assi.</span></center>


===Configuring series===
La prima cosa che si trova nello strumento degli assi è il selettore degli assi attivi. Siccome gli assi attivi sono gli ultimi, ora è attivo il sistema 1. Lo strumento degli assi, come lo strumento delle etichette, permette di impostare gli assi attivi, consentendo di tracciare più dati negli stessi assi (compreso aggiungere o rimuovere gli assi). Per il momento si lavora sul sistema di assi selezionato, che è quello associato alle funzioni trigonometriche.
Set series properties as we did in [[Plot_Basic_tutorial|previous tutorial]].


===Showing grid and legend===
Nei cursori delle dimensioni, spostare a sinistra i cursori orizzontali e in basso quelli verticali per ridurre le dimensioni degli assi (cercare di emulare l'esempio). Dopo impostare l'allineamento degli assi, spostarli in alto a destra impostando un piccolo offset di due unità.
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).
===Configurare le serie===


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.
Impostare le proprietà delle serie, come descritto nella [[Plot_Basic_tutorial/it|guida di base]].


===Setting axes labels===
===Mostrare la griglia e la legenda===
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:

La griglia e legenda sono mostrate e nascoste con gli stessi strumenti utilizzati nel [[Plot_Basic_tutorial/it|tutorial precedente]], ma in questo caso il comportamento è un po' diverso a causa della presenza di due diversi sistemi di assi.

Per quanto concerne le linee della griglia, è possibile visualizzarle indipendentemente per ogni set di assi, e, ad esempio, se ora si prova a mostrare la griglia viene mostrata solo la griglia delle funzioni trigonometriche. Per visualizzare la griglia della funzione polinomiale prima si devono attivare gli assi 0 (utilizzando lo strumento di configurazione degli assi) e poi utilizzare nuovamente lo strumento della griglia (è possibile che sia necessario premerlo due volte).

Per quanto riguarda la legenda, essa è unica per entrambi i sistemi di assi ed è possibile scegliere quali assi utlizzare per mostrarla, ma si consiglia vivamente di utilizzare i più grandi (0 in questo esempio) perché la posizione viene riferita alle coordinate di questi assi. Se adesso si visualizza la legenda si può osservare che è posizionata male, questo problema sarà risolto in seguito.

===Stabilire i titoli===

È possibile impostare le etichette degli assi con lo stesso strumento utilizzato nella [[Plot_Basic_tutorial/it|guida di base]], con la differenza che ora ci sono più assi. Dal momento che le etichette degli assi sono una per ogni asse, non è una differenza significativa, ma il modulo [[Plot_Module/it|Grafico]] di FreeCAD consente anche di impostare un titolo per il sistema di assi. Ecco come impostare solo il titolo degli assi principali:


'''Axes 0:'''
'''Axes 0:'''
Line 87: 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.
Impostare inoltre 20 come fontsize per tutti, escluso il titolo che utilizza una dimensione di scrittura di 24. Come accaduto con la legenda, il titolo è posizionato male, interseca gli assi del secondo set, quindi ora bisogna risolvere entrambi i problemi.

===Riposizionare gli elementi del grafico===

Il modulo [[Plot_Module/it|Grafico]] di FreeCAD fornisce uno strumento per impostare la posizione di alcuni elementi del grafico, come titoli, etichette o legenda.


===Setting elements position===
[[Image:Plot_Positions.png‎|center|Icona dello strumento Posizione]]
[[Plot_Module|FreeCAD Plot module]] provides a tool in order to set the position of several plot elements, as titles, labels or legend.
<center><span style="font-variant:small-caps">Icona dello strumento Posizione.</span></center>


[[Image:Plot_Positions.png‎|center|Position editor icon]]
Quando si esegue lo strumento viene visualizzato un elenco con tutti gli elementi riposizionabili. I titoli e la legenda possono essere spostati in tutte le direzioni, invece le etichette degli assi possono essere mossi solo sulla direzione assi. Selezionare il titolo degli assi 0 e spostarlo in (0.24,1.01), quindi selezionare la legenda e spostarla in una posizione migliore. È anche possibile aumentare la dimensione dei caratteri delle etichette della legenda.
<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.
==Salvare il grafico==


==Saving plot==
Ora è possibile salvare il lavoro. Consultare il [[Plot_Basic_tutorial/it|tutorial di base]] se non si ricorda come farlo.
Now you can save your work. See [[Plot_Basic_tutorial|previous tutorial]] if you don't remeber how to do it.


[[Category:Tutorials]]
{{PlotTools/it}}


[[Category:Tutorials/it]]


{{clear}}
{{languages/it | {{en|Plot_MultiAxes_tutorial}} {{es|Plot_MultiAxes_tutorial/es}} {{fr|Plot_MultiAxes_tutorial/fr}} }}
<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.