Commit 0163fafd authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch 'begin-tuto' into 'master'

try readme.md

See merge request !4
parents 4824037c fc5058c5
Get started
===========
for the online version see https://gitlab.aip.de/yfournier/mypltemplate/wikis/get-started
A. Install the template module
------------------------------
......
# Summary
1. [Install the module mypltemplate](https://gitlab.aip.de/yfournier/mypltemplate/wikis/get-started#1-install-the-module-mypltemplate)
2. [Plotting some Examples](https://gitlab.aip.de/yfournier/mypltemplate/wikis/get-started#2-plotting-some-examples)
3. [Examples](https://gitlab.aip.de/yfournier/mypltemplate/wikis/get-started#3-examples)
# 1. Install the module mypltemplate
> **NOTES:** STEP 3 has two version with and without an account at gitlab.aip.de
## STEP 1: download source
download the source of the module mypltemplate:
- [zip](https://gitlab.aip.de/yfournier/mypltemplate/repository/archive.zip?ref=master)
- [tar.gz](https://gitlab.aip.de/yfournier/mypltemplate/repository/archive.tar.gz?ref=master)
## STEP 2: extract and rename the module
you can rename `mypltemplate` to any name you whish.
> **NOTES:** for the exemple we rename it to `mymodule` in the directory `/home/user/src/`
> (python requires that module name should be only letters)
## STEP 3: Clone myplotlib from gitlab.aip.de **(with account at gitlab.aip.de)**
in `/home/user/src/mymodule`:
```
git git@gitlab.aip.de:yfournier/myplotlib.git --branch tools
```
## STEP 3: download source **(without an account at gitlab.aip.de)**
download source of the module myplotlib
- [zip](https://gitlab.aip.de/yfournier/myplotlib/repository/archive.zip?ref=tools)
- [tar.gz](https://gitlab.aip.de/yfournier/myplotlib/repository/archive.tar.gz?ref=tools)
extract and rename like `/home/user/src/mymodule/myplotlib`
## STEP 4: testing `myplotlib`
in `/home/user/src/mymodule/`
```
python2.7 -m myplotlib -t
```
This will execute a series of tests, they should all be successful.
## STEP 5: Enjoy!
Now you can start to enjoy the power of `myplotlib`
# 2. Plotting some Examples
## STEP 1: launch python2.7
```
python2.7
```
## STEP 2: Import the module.
```python
# IMPORT the MODULE
from mymodule import *
```
This imports all variables, functions and classes from `mymodule/__init__.py`
## STEP 3: Open and Access some data
The template modules has some dummy data for demonstration in `mymodule/data`
This data are of two type:
- some **structured datasets** (run1.txt, run2.txt, ...)
- some **database-like datasets** (serie1.txt, serie2.txt)
In python (this is a general remark) it exists two powerful objects for
storing and accessing these types of data.
- for **structured datasets** the python **dictionaries** are suitable (see [doc](https://docs.python.org/2/tutorial/datastructures.html#dictionaries))
- for **database-like datasets** the **numpy.recarray** are the perfect tool (see [doc](https://docs.scipy.org/doc/numpy/reference/generated/numpy.recarray.html))
In `mymodule/myIOs` are two files containing the functions `readRun`, and `readSeries`
- the function `readRun` reads a run-text-file (structured data set) and stores the information into a python dictionary.
- the function `readSeries` reads a series-text-file (database data set) and stores the data into a numpy recarray.
Both function returns the data container of myplotlib, `MyData`
```python
# READ Some data
run1 = readRun('./mymodule/data/serie1/run1.txt')
```
now you can now type
```python
run1
>>> <mymodule.myplotlib.myData.MyData instance at ...>
```
As you can see the object `run1` is an instance of type `MyData`. The `...` shows the address of the instance in the memory.
This identifier is unique (again this is a general remark for python).
Now you can access the name of the run, the vaue of input1 or the matrix of the results by simply typing:
```python
run1.data['name']
run1.data['input1']
run1.data['results']
...
```
## STEP 4: Visualising the data
In `mymodule/myAxes` are a few examples of axes classes.
These classes are build over a general class `MyAxes` (from myplotlib). The class `MyAxes`
is build such that it can be used with any user-defined class build on `MyFig`.
We will start with the class `AxResults` (see `axResults.py`)
In order to plot the axes we need to integrate it into a figure.
For the comfort of the user, `myplotlib` comes with a few standard classes like `FigOneAxes3D` (see myplotlib/mytools/figOneAxes3D.py).
This class is build over `MyFig` (compatible with any `MyAxes`) and can be used as a container
for a single `MyAxes` instances.
We can now create a figure `fig` of type `FigOneAxes3D` with the
dataset `(run1,)` given to the axes class `AxResults`.
```python
# Create a figure
fig = FigOneAxes3D((run1,), AxResults)
```
you can now type:
```python
fig
>>> <mymodule.myplotlib.mytool.figOneAxes3D.FigOneAxes3D at ...>
```
We can also access the axes:
```python
fig.get_axes()
>>> [<mypltemplate.myAxes.axResults.AxResults at ...>]
```
or even store the axes into a variable:
```python
ax = fig.get_axes()[0]
ax
>>> <mypltemplate.myAxes.axResults.AxResults at ...>
```
The object `fig` has (alike any `MyFig` instance) a function `plot()`
The `plot` function will call all `plotting` function of all axes contained in `fig`.
> For this example only `ax.plotting()`.
The `plotting` function will act on some attributes of ax.
> For instance it will change the label.
```python
# The label of the axes before plotting
ax.get_xlabel()
>>> u''
# CALL the PLOT procedure
fig.plot()
# The label after plotting
ax.get_xlabel()
>>> u'${\\rm x}~[{\\rm m}]$'
```
As you can see any part of the object can be access.
for more details see matplotlib documentation (see [doc](http://matplotlib.org/api/axes_api.html))
Now it is time to show the data set on the screen. To do so `myplotlib`
comes with a class called `MyWin`. This class will create a window,
containing a canvas.
- The **window** has some buttons like close, reduce and so one...
- The **canvas** can be seen as a white sheet of paper
on which you will draw a figure (only one figure can be drawn on a canvas).
```python
# Create a window where the figure is shown
win = MyWin(fig)
```
This should produce a window on which `fig` should be plotted.
# 3. Examples
## What you just did
```python
# Import the module
from mymodule import *
# Read some data
run1 = readRun('./mymodule/data/serie1/run1.txt')
# Create a figure
fig = FigOneAxes3D((run1,), AxResults)
# Create a window where the figure is shown
win = MyWin(fig)
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment