Plot Basic tutorial/ru: Difference between revisions
(Created page with "{{TutorialInfo/ru |Topic=Plot Workbench |Level=Beginner |Time= |Author= |FCVersion= |Files= }}") |
(Updating to match new version of source page) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
|||
<div class="mw-translate-fuzzy"> |
|||
{{TutorialInfo/ru |
{{TutorialInfo/ru |
||
|Topic=Plot Workbench |
|Topic=Plot Workbench |
||
Line 7: | Line 10: | ||
|Files= |
|Files= |
||
}} |
}} |
||
</div> |
|||
In this tutorial we will learn how to |
In this tutorial we will learn how to create a basic plot using the [[Plot_Workbench|Plot Workbench]] and the [[Python_console|Python console]]. |
||
[[Image:Plot_Trigonometric_Example.png|600px |
[[Image:Plot_Trigonometric_Example.png|600px]] |
||
{{Caption|Basic plot example}} |
|||
In |
In the image you can see the result that we will approximately obtain. Following this tutorial you will learn: |
||
* How to create a Plot from Python |
* How to create a Plot from the [[Python_console|Python console]]. |
||
* How to plot some data from Python |
* How to plot some data from the [[Python_console|Python console]]. |
||
* How to show the grid lines. |
* How to show the [[Image:Plot_Grid.svg|24px]] [[Plot_Grid|grid lines]]. |
||
* How to show the legend. |
* How to show the [[Image:Plot_Legend.svg|24px]] [[Plot_Legend|legend]]. |
||
* How to edit series labels, introducing text in [http://www.latex-project.org LaTeX]. |
* How to edit [[Image:Plot_Series.svg|24px]] [[Plot_Series|series labels]], introducing text in [http://www.latex-project.org LaTeX]. |
||
* How to edit axes labels, introducing text in [http://www.latex-project.org LaTeX]. |
* How to edit [[Image:Plot_Labels.svg|24px]] [[Plot_Labels|axes labels]], introducing text in [http://www.latex-project.org LaTeX]. |
||
* How to edit series styles. |
* How to edit series styles. |
||
* How to save your plot. |
* How to save your plot. |
||
==Plotting data== |
==Plotting data== |
||
In order to plot data you don't need to create a new FreeCAD document, simply show the Python console and start sending commands, or use [[Macros|macros]]. |
|||
To plot data you don't need a FreeCAD document, simply open the [[Python_console|Python console]] and start sending commands, or use [[Macros|macros]]. |
|||
===Creating plot document=== |
===Creating plot document=== |
||
Plots are special documents that can be created manually in order to add data later, or allow the module creates one authomatically when you start plotting data. Create your own plot documents have 2 advantages: |
|||
Plots are special documents that can be created manually in order to add data later, or the workbench can create one automatically when you start plotting data. Creating your own plot document has two advantages: |
|||
* You can set the document window label. |
* You can set the document window label. |
||
* You can control |
* You can control the document where you plot your data. |
||
To create a new plot document simply launch the following commands: |
|||
{{Code|code= |
|||
try: |
|||
from FreeCAD.Plot import Plot |
|||
except ImportError: |
|||
from freecad.plot import Plot |
|||
In order to create new plot document simply launch following commands: |
|||
<syntaxhighlight> |
|||
import Plot |
|||
Plot.figure("TrigonometricTest") |
Plot.figure("TrigonometricTest") |
||
}} |
|||
</syntaxhighlight> |
|||
That will create a new tab on main windows called '''TrigonometricTest'''. The new created document already have a set of axes. Each plot document have at least one set of axes that can be removed without using fully matplotlib control. |
|||
In FreeCAD version 0.19 it is required to install the [[Image:Workbench_Plot.svg|24px]] [[Plot_Workbench|Plot Workbench]] with the [[Std_AddonMgr|Add-on manager]], while from FreeCAD version 0.20 onward the external add-on is no longer required to perform plots. |
|||
The commands above will create a new tab in the [[Main_view_area|Main view area]] called '''TrigonometricTest'''. The newly created document already has a set of axes. Each plot document has at least one set of axes. |
|||
===Drawing functions=== |
===Drawing functions=== |
||
You can start working here due to plot command will start a new document, but all plot commands that you execute will append series to created plot until you don't create a new document, so ussually is better options control the opened plot documents. First thing that we need to do is create the data for sine and cosine functions that we want to plot: |
|||
You can also start working from here because, as already explained, the plot command will create a new document if required. The next thing we need to do is create the data for the sine and cosine functions that we want to plot: |
|||
<syntaxhighlight> |
|||
{{Code|code= |
|||
import math |
import math |
||
t = range(0,101) |
t = range(0,101) |
||
Line 46: | Line 61: | ||
s = [math.sin(2.0*math.pi*tt) 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] |
c = [math.cos(2.0*math.pi*tt) for tt in t] |
||
}} |
|||
</syntaxhighlight> |
|||
That will create 3 arrays of data (with 101 points): |
That will create 3 arrays of data (with 101 points): |
||
* ''t'' = Time in seconds. |
* ''t'' = Time in seconds. |
||
Line 52: | Line 68: | ||
* ''c'' = Cosine function. |
* ''c'' = Cosine function. |
||
In order to plot both |
In order to plot both functions we only need to launch the next commands: |
||
<syntaxhighlight> |
|||
{{Code|code= |
|||
Plot.plot(t,s) |
Plot.plot(t,s) |
||
Plot.plot(t,c) |
Plot.plot(t,c) |
||
}} |
|||
</syntaxhighlight> |
|||
That will plot our functions. '''plot''' command allows the series label as argument, but since we will edit it later using Plot module tools we don't pass this data yet. |
|||
The '''plot''' command allows the series label as an argument, but since we will edit it later using the Plot workbench tools, we don't pass this data yet. |
|||
==Configuring plot== |
==Configuring plot== |
||
===Showing grid and legend=== |
===Showing grid and legend=== |
||
Change FreeCAD workbench to [[Plot_Module|Plot module]] in View/Workbench menu. When module has been loaded use grid tool in order to show it. |
|||
Change the FreeCAD workbench to the [[Plot_Workbench|Plot Workbench]] with {{MenuCommand|View → Workbench → Plot}} (you must install the add-on first with the [[Std_AddonMgr|Add-on manager]]). When the workbench has been loaded, use the [[Plot_Grid|grid tool]] to show the grid. |
|||
[[Image:Plot_Grid.png|center|Show/hide grid tool icon]] |
|||
<center><span style="font-variant:small-caps">Show/hide grid tool icon.</span></center> |
|||
[[Image:Plot_Grid.svg]] |
|||
You can repeat the action in order to hide it. Also you can show the legend with the tool provided. |
|||
{{Caption|Show/hide grid tool icon}} |
|||
You can repeat the action to hide the grid. Use the [[Plot_Legend|legend tool]] to show, or hide, the legend. |
|||
[[Image:Plot_Legend.png|center|Show/hide legend tool icon]] |
|||
<center><span style="font-variant:small-caps">Show/hide legend tool icon.</span></center> |
|||
[[Image:Plot_Legend.svg]] |
|||
As you can see, legend is empty because we have not set any series label yet. In [[Plot_Module|Plot module]] series without label are not represented at legend, in order to allow you to draw auxiliar lines. |
|||
{{Caption|Show/hide legend tool icon}} |
|||
As you can see, the legend is very small and empty because we have not set any series label yet. In the [[Plot_Workbench|Plot Workbench]] series without a label are not displayed in the legend. |
|||
===Setting series labels=== |
|||
With the series tool you can edit some series parameters. |
|||
===Setting series label=== |
|||
[[Image:Plot_Series.png|center|Series configuration tool icon]] |
|||
<center><span style="font-variant:small-caps">Series configuration tool icon.</span></center> |
|||
With the [[Plot_Series|series tool]] you can edit the parameters of each series. |
|||
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: |
|||
<syntaxhighlight> |
|||
[[Image:Plot_Series.svg]] |
|||
{{Caption|Series configuration tool icon}} |
|||
Select the series you want to edit, we will start with the first one. Uncheck '''No label''' and set this label: |
|||
{{Code|code= |
|||
$y = \sin \left( 2 \pi t \right)$ |
$y = \sin \left( 2 \pi t \right)$ |
||
}} |
|||
</syntaxhighlight> |
|||
Since [http://matplotlib.org/ matplotlib] supports [http://www.latex-project.org LaTeX] you can set all the labels or titles that you want using it. Set the following label to second serie: |
|||
Since [http://matplotlib.org/ matplotlib] supports [http://www.latex-project.org LaTeX] you can set all labels and titles using LaTeX. Set the following label for the second series: |
|||
<syntaxhighlight> |
|||
{{Code|code= |
|||
$y = \cos \left( 2 \pi t \right)$ |
$y = \cos \left( 2 \pi t \right)$ |
||
}} |
|||
</syntaxhighlight> |
|||
===Setting series style=== |
===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. |
|||
You can set many series properties. Try to set the properties shown in the example image, changing the colors and drawing style of the second series. |
|||
===Setting axes labels=== |
===Setting axes labels=== |
||
With the labels tool you can set labels associated to all created axes. |
|||
With the [[Plot_Labels|labels tool]] you can set the title and the labels for the axes. |
|||
[[Image:Plot_Labels.png|center|Labels tool icon]] |
|||
<center><span style="font-variant:small-caps">Labels tool icon.</span></center> |
|||
[[Image:Plot_Labels.svg]] |
|||
{{Caption|Labels tool icon}} |
|||
Set this data: |
Set this data: |
||
Line 102: | Line 128: | ||
* Y Label = $y = \mathrm{f} \left( t \right)$ |
* Y Label = $y = \mathrm{f} \left( t \right)$ |
||
Also change the size of |
Also change the font size of the title and all labels to 20. |
||
==Saving plot== |
==Saving plot== |
||
With saving plot tool you can save your plot as image file in several formats. |
|||
With the [[Plot_Save|save tool]] you can save your plot as an image file in several formats. |
|||
[[Image:Plot_Save.png|center|Save tool icon]] |
|||
<center><span style="font-variant:small-caps">Save tool icon.</span></center> |
|||
[[Image:Plot_Save.svg]] |
|||
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. |
|||
{{Caption|Save tool icon}} |
|||
First select the path and filename for the output file. |
|||
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. |
|||
Set the output image size in inches, for example use 11.7x8.3 to get a '''DIN A4''' size. DPI (Dots per inch) will control the image resolution, for example use 100 dpi. In combination with the given dimensions this will result in an image of 1170x830 pixels. |
|||
{{Plot_Tools_navi{{#translation:}}}} |
|||
{{clear}} |
|||
{{Userdocnavi{{#translation:}}}} |
|||
<languages/> |
|||
[[Category:External_Workbenches{{#translation:}}]] |
|||
[[Category:Addons{{#translation:}}]] |
Latest revision as of 13:00, 14 April 2023
Руководство |
Тема |
---|
Plot Workbench |
Уровень |
Beginner |
Время для завершения |
Авторы |
FreeCAD версия |
Примеры файлов |
Смотрите также |
None |
In this tutorial we will learn how to create a basic plot using the Plot Workbench and the Python console.
Basic plot example
In the image you can see the result that we will approximately obtain. Following this tutorial you will learn:
- How to create a Plot from the Python console.
- How to plot some data from the Python console.
- How to show the grid lines.
- How to show the legend.
- How to edit series labels, introducing text in LaTeX.
- How to edit axes labels, introducing text in LaTeX.
- How to edit series styles.
- How to save your plot.
Plotting data
To plot data you don't need a FreeCAD document, simply open the Python console and start sending commands, or use macros.
Creating plot document
Plots are special documents that can be created manually in order to add data later, or the workbench can create one automatically when you start plotting data. Creating your own plot document has two advantages:
- You can set the document window label.
- You can control the document where you plot your data.
To create a new plot document simply launch the following commands:
try:
from FreeCAD.Plot import Plot
except ImportError:
from freecad.plot import Plot
Plot.figure("TrigonometricTest")
In FreeCAD version 0.19 it is required to install the Plot Workbench with the Add-on manager, while from FreeCAD version 0.20 onward the external add-on is no longer required to perform plots. The commands above will create a new tab in the Main view area called TrigonometricTest. The newly created document already has a set of axes. Each plot document has at least one set of axes.
Drawing functions
You can also start working from here because, as already explained, the plot command will create a new document if required. The next thing we need to do is create the data for the sine and cosine functions that we want to plot:
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]
That will create 3 arrays of data (with 101 points):
- t = Time in seconds.
- s = Sine function.
- c = Cosine function.
In order to plot both functions we only need to launch the next commands:
Plot.plot(t,s)
Plot.plot(t,c)
The plot command allows the series label as an argument, but since we will edit it later using the Plot workbench tools, we don't pass this data yet.
Configuring plot
Showing grid and legend
Change the FreeCAD workbench to the Plot Workbench with View → Workbench → Plot (you must install the add-on first with the Add-on manager). When the workbench has been loaded, use the grid tool to show the grid.
Show/hide grid tool icon
You can repeat the action to hide the grid. Use the legend tool to show, or hide, the legend.
Show/hide legend tool icon
As you can see, the legend is very small and empty because we have not set any series label yet. In the Plot Workbench series without a label are not displayed in the legend.
Setting series label
With the series tool you can edit the parameters of each series.
Series configuration tool icon
Select the series you want to edit, 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 labels and titles using LaTeX. Set the following label for the second series:
$y = \cos \left( 2 \pi t \right)$
Setting series style
You can set many series properties. Try to set the properties shown in the example image, changing the colors and drawing style of the second series.
Setting axes labels
With the labels tool you can set the title and the labels for the axes.
Labels tool icon
Set this data:
- Title = Trigonometric functions example
- X Label = $t$
- Y Label = $y = \mathrm{f} \left( t \right)$
Also change the font size of the title and all labels to 20.
Saving plot
With the save tool you can save your plot as an image file in several formats.
Save tool icon
First select the path and filename for the output file.
Set the output image size in inches, for example use 11.7x8.3 to get a DIN A4 size. DPI (Dots per inch) will control the image resolution, for example use 100 dpi. In combination with the given dimensions this will result in an image of 1170x830 pixels.
- Начинающим
- Установка: Загрузка, Windows, Linux, Mac, Дополнительных компонентов, Docker, AppImage, Ubuntu Snap
- Базовая: О FreeCAD, Интерфейс, Навигация мыши, Методы выделения, Имя объекта, Настройки, Верстаки, Структура документа, Свойства, Помоги FreeCAD, Пожертвования
- Помощь: Учебники, Видео учебники
- Верстаки: Std Base, Arch, Assembly, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Surface, TechDraw, Test Framework