Plot Basic tutorial/pl: Difference between revisions

From FreeCAD Documentation
No edit summary
(Created page with "Możesz powtórzyć tę czynność, aby ją ukryć. Możesz również wyświetlić legendę za pomocą dostarczonego narzędzia.")
Line 74: Line 74:
<center><span style="font-variant:small-caps">Ikona narzędzia siatki - pokaż / ukryj.</span></center>
<center><span style="font-variant:small-caps">Ikona narzędzia siatki - pokaż / ukryj.</span></center>


Możesz powtórzyć tę czynność, aby ją ukryć. Możesz również wyświetlić legendę za pomocą dostarczonego narzędzia.
You can repeat the action in order to hide it. Also you can show the legend with the tool provided.


[[Image:Plot_Legend.svg‎|center|Show/hide legend tool icon]]
[[Image:Plot_Legend.svg‎|center|Show/hide legend tool icon]]

Revision as of 10:41, 5 September 2021

Ćwiczenie
Temat
Poradnik: Podstawy środowiska pracy Wykres
Poziom trudności
Początkujący
Czas wykonania
nie określono
Autorzy
-
Wersja FreeCAD
-
Pliki z przykładami
brak
Zobacz również
-

W tym poradniku dowiemy się, jak wykonać podstawowy wykres przy użyciu środowiska pracy Wykres i konsoli Python.

Przykład prostego wykresu
Przykład prostego wykresu
Przykład prostego wykresu.

Na poprzednim obrazku możesz zobaczyć rezultat, jaki w przybliżeniu uzyskamy. Po tym poradniku nauczysz się:

Wykreślanie danych

Aby wykreślić dane nie musisz tworzyć nowego dokumentu FreeCAD, wystarczy, że uruchomisz konsolę Pythona i zaczniesz wysyłać komendy, lub użyjesz makrodefinicji.

Tworzenie dokumentu wykresu=

Wykresy są specjalnymi dokumentami, które można utworzyć ręcznie w celu późniejszego dodania danych, lub pozwolić, aby moduł utworzył je automatycznie w momencie rozpoczęcia wykreślania danych. Tworzenie własnych dokumentów wykresów ma 2 zalety:

  • Możesz ustawić etykietę okna dokumentu.
  • Możesz łatwo kontrolować, na którym dokumencie wykreślać dane.

Aby utworzyć nowy dokument działki wystarczy uruchomić następujące komendy:

import Plot
Plot.figure("TrigonometricTest")

Spowoduje to utworzenie nowej zakładki w głównym oknie o nazwie TrigonometricTest. Nowo utworzony dokument posiada już zestaw osi. Każdy dokument wykresu posiada co najmniej jeden zestaw osi, które mogą być usunięte bez użycia pełnej kontroli biblioteki matplotlib.

Funkcje rysowania

Możesz zacząć pracę tutaj, ponieważ polecenie plot rozpocznie nowy dokument, ale wszystkie polecenia plot, które wykonasz będą dołączać serie do utworzonego wykresu, dopóki nie utworzysz nowego dokumentu, więc zazwyczaj lepiej jest kontrolować otwarte dokumenty wykresów. Pierwszą rzeczą jaką musimy zrobić jest utworzenie danych dla funkcji sinus i cosinus, które chcemy wykreślić:

import math
t = range(0,101)
t = [tt/100.0 for tt in t]
s = [math.sin(2.0*math.pi*tt) for tt in t]
c = [math.cos(2.0*math.pi*tt) for tt in t]

Spowoduje to utworzenie 3 tablic danych (ze 101 punktami):

  • t = Czas w sekundach.
  • s = Funkcja sinus.
  • c = funkcja cosinus.

W celu wykreślenia obu funkcji wystarczy uruchomić kolejne komendy:

Plot.plot(t,s)
Plot.plot(t,c)

Spowoduje to wykreślenie naszych funkcji. Polecenie plot' dopuszcza jako argument etykietę serii, ale ponieważ będziemy ją później edytować za pomocą narzędzi modułu Plot, nie przekazujemy jeszcze tych danych.

Konfiguracja wykresu

Wyświetlanie siatki i legendy

Zmień środowisko pracy FreeCAD na Wykres w menu Widok → Środowiska pracy. Po załadowaniu modułu użyj narzędzia siatki, aby ją wyświetlić.

Ikona narzędzia siatki - pokaż / ukryj
Ikona narzędzia siatki - pokaż / ukryj
Ikona narzędzia siatki - pokaż / ukryj.

Możesz powtórzyć tę czynność, aby ją ukryć. Możesz również wyświetlić legendę za pomocą dostarczonego narzędzia.

Show/hide legend tool icon
Show/hide legend tool icon
Show/hide legend tool icon.

As you can see, legend is empty because we have not set any series label yet. In Plot module series without label are not represented at legend, in order to allow you to draw auxiliary lines.

Setting series labels

With the series tool you can edit some series parameters.

Series configuration tool icon
Series configuration tool icon
Series configuration tool icon.

First for all select the line that you want to edit, for example we will start with the first one. Uncheck No label and set this label:

$y = \sin \left( 2 \pi t \right)$

Since matplotlib supports LaTeX you can set all the labels or titles that you want using it. Set the following label to second serie:

$y = \cos \left( 2 \pi t \right)$

Setting series style

Series allows you to set a lot of series properties. Try to set the properties shown at the example image, changing series colors and drawing style of the second one.

Setting axes labels

With the labels tool you can set labels associated to all created axes.

Labels tool icon
Labels tool icon
Labels tool icon.

Set this data:

  • Title = Trigonometric functions example
  • X Label = $t$
  • Y Label = $y = \mathrm{f} \left( t \right)$

Also change the size of all of them to 20.

Saving plot

With saving plot tool you can save your plot as image file in several formats.

Save tool icon
Save tool icon
Save tool icon.

First for all select the path of the output file. You can use file selection dialog using the button at right of the path edition line.

You can set the output image size in inches, for example we can set 11.7x8.3 that is a DIN A4 paper size. DPI (Dots per inch) will control the image resolution, for example using 100 dpi you will get an image of 1170x830 pixels. Template:Tutorials navi/pl