Plot MultiAxes tutorial/it: Difference between revisions

From FreeCAD Documentation
(Created page with "==Configurare il grafico==")
(Created page with "===Configurare gli assi=== Il modulo Grafico di FreeCAD fornisce uno strumento per modificare le proprietà di ogni asse.")
Line 48: Line 48:
==Configurare il grafico==
==Configurare il grafico==


===Configuring axes===
===Configurare gli assi===

[[Plot_Module|FreeCAD Plot module]] provides a tool in order to modify the properties of each axes.
Il modulo [[Plot_Module/it|Grafico]] di FreeCAD fornisce uno strumento per modificare le proprietà di ogni asse.


[[Image:Plot_Axes.png‎|center|Axes configuration tool icon]]
[[Image:Plot_Axes.png‎|center|Axes configuration tool icon]]

Revision as of 21:00, 5 December 2014

Prima di seguire questo tutorial è bene leggere la guida di base sui Grafici.
In questo tutorial si descrive come creare e modificare un Grafico MultiAsse.
Consultare anche la sezione Modulo Grafico.

Esempio di grafico multiasse
Esempio di grafico multiasse
Esempio di grafico multiasse.

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 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 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.
I seguenti comandi creano i gruppi di dati necessari:

 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]

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.
In FreeCAD il grafico Multiasse è destinato a produrre un grafico con più assi, e non per produrre più grafici nello stesso documento.

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).
Per tracciare la prima curva basta lanciare i seguenti comandi:

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

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 LaTeX).

Per tracciare le funzioni trigonometriche è necessario creare prima dei nuovi assi.
Nel modulo 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.plot(t,s,r"$\sin\left( 2 \pi t \right)$")
 Plot.plot(t,c,r"$\cos\left( 2 \pi t \right)$")

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 Grafico di FreeCAD.

Configurare il grafico

Configurare gli assi

Il modulo Grafico di FreeCAD fornisce uno strumento per modificare le proprietà di ogni asse.

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.