README.md 7.61 KB
Newer Older
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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`:

```
29
git clone git@gitlab.aip.de:yfournier/myplotlib.git --branch v2.2.2a
30
31
cd myplotlib/
cp config-default.py config.py
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
32
33
34
35
36
37
```

## STEP 3: download source **(without an account at gitlab.aip.de)**

download source of the module myplotlib

38
39
- [zip](https://gitlab.aip.de/yfournier/myplotlib/repository/archive.zip?ref=v2.2.2a)
- [tar.gz](https://gitlab.aip.de/yfournier/myplotlib/repository/archive.tar.gz?ref=v2.2.2a)
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
40
41
42

extract and rename like `/home/user/src/mymodule/myplotlib`

43
44
45
46
47
48
49
then setup:

```
cd myplotlib/
cp config-default.py config.py
```

50
51
52
## STEP 4: testing

### testing `myplotlib`
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
53
54
55
56

in `/home/user/src/mymodule/`

```
57
python2.6 -m myplotlib.__main__ -t
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
58
python2.7 -m myplotlib -t
59
python3 -m myplotlib -t
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
60
61
62
63
```

This will execute a series of tests, they should all be successful.

Yori Fournier's avatar
Yori Fournier committed
64
65
66
67
> **REMARK**: If you get some errors with python2.6 try to remove the latex, ticks.minor and ticks.major configurations in `myplotlib/__init__.py`

> **REMARK**: If you get some errors with python >2.6 try to set the latex option in `myplotlib/__init__.py` to False

68
69
70
71
72
### testing `mymodule`

in `/home/user/src/`

```
73
python2.6 -m mymodule.__main__ -t
74
python2.7 -m mymodule -t
75
python3 -m mymodule -t
76
77
78
79
80
```

This will execute a series of 3 tests, they should all be successful.


Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
## 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)
```
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

## Switch dataset
```python
# Import the module
from mymodule import *

# Read some data
run1 = readRun('./mymodule/data/serie1/run1.txt')
run2 = readRun('./mymodule/data/serie1/run2.txt')

# Create a figure
fig = FigOneAxes3D((run1,), AxResults)

# Create a window where the figure is shown
win = MyWin(fig)

# Switch from run1 to run2
fig.update(rawdata=(run2,))

# Actualize the window
win.refresh()
```

## Plot AxMaxResults et AxParameterSpace with data serie1

```python
# Import the module
from mymodule import *

# Read some data
serie1 = readRun('./mymodule/data/serie1/serie1.txt')

# Create a figure figmax
figmax = FigOneAxes2D((serie1,), AxMaxResults)

# Create a window winmax
winmax = MyWin(figmax, fignum=0)

# Create a figure
figps = FigOneAxes2D((serie1,), AxParameterSpace)

# Create a window winps
winps = MyWin(figps, fignum=1)
```