... | ... | @@ -18,32 +18,33 @@ alike in matplotlib a plot is composed of four type of objects: |
|
|
|
|
|
> **NOTE**: If you have not read yet the page about axes you should start [there](Create your first axes)
|
|
|
|
|
|
It is always a good idea to design figures, the sub-module mytools of myplotlib offers a few standard figure classes
|
|
|
that are very practical for testing and fast development purposes but at the end you may want to access some more
|
|
|
specific features.
|
|
|
It is always a good idea to design figures, the sub-module mytools of myplotlib offers a few standard figure classes (FigOneAxes2D, ...)
|
|
|
that are very practical for testing and fast development purposes, but at the end of the day you may want to access some more specific features.
|
|
|
|
|
|
As just mentioned a figure is a container for axes. Indeed a figure may contain a few axes. This is practical
|
|
|
for comparison, completeness, or user specific legends.
|
|
|
A figure is a container for axes, and often it is useful to have several axes on the same figure,
|
|
|
either for comparison, completeness, or user specific legends.
|
|
|
Indeed, alike in matplotlib, colorbars and legends are axes.
|
|
|
|
|
|
Indeed in matplotlib colorbars and legends are axes. In myplotlib too.
|
|
|
The difference is that myplotlib provides an additional feature to figures: **user-specific keywords!**
|
|
|
|
|
|
The difference is that in myplotlib figures have a one additional feature: **user-specific keywords!**
|
|
|
Keywords are very practical, you can access them from all axes functions, these are the global variables of the figure.
|
|
|
A further advantage they can be passed to the figure while creation and can be modified on the fly with the update
|
|
|
function.
|
|
|
|
|
|
keywords are very practical you can access them from any axes functions. These are the global variables of the figure.
|
|
|
one more advantage of keywords they can, passed to the figure while creating it and can be modified on the fly with
|
|
|
the function update.
|
|
|
Therefore `MyFig` (the figure *base class* in myplotlib) has two functions that can be overwritten:
|
|
|
- *declareKeywords*: where you declare the keywords you need and there default values. (tech: create a fig.keywords dict)
|
|
|
- *addAxes*: the function where you tell the figure which axes to use and where to put them. (tech: uses fig.add_axes())
|
|
|
|
|
|
|
|
|
# The class FigMyFirstFigure
|
|
|
|
|
|
# The class AxMyFirstAxes
|
|
|
Create `mymodule/myFigures/<name of my class>.py`
|
|
|
|
|
|
Create `mymodule/myAxes/<name of my class>.py`
|
|
|
|
|
|
> Here we will use mymodule/myAxes/axMyFirstAxes.py
|
|
|
> Here we will use mymodule/myFigures/figMyFirstFigure.py
|
|
|
|
|
|
```python
|
|
|
# Import the mother class MyAxes from the local myplotlib module
|
|
|
from ..myplotlib import MyAxes
|
|
|
# Import the mother class MyFig from the local myplotlib module
|
|
|
from ..myplotlib import MyFig
|
|
|
|
|
|
# Here you can also import any needed module
|
|
|
# ex: from .. import np
|
... | ... | @@ -51,54 +52,34 @@ from ..myplotlib import MyAxes |
|
|
|
|
|
|
|
|
# Begin of the class
|
|
|
class axMyFirstAxes(MyAxes):
|
|
|
|
|
|
# This is the function that will format the rawdata so that they can be plotted
|
|
|
def formatRawdata(self, rawdata):
|
|
|
|
|
|
|
|
|
# Extract some part of the data
|
|
|
rawdata1 = rawdata.data[<some key>]
|
|
|
rawdata2 = rawdata.data[<some key>]
|
|
|
|
|
|
# Format the data
|
|
|
if(self.fig.keywords[<some key>]):
|
|
|
# format in a certain way
|
|
|
else:
|
|
|
# format in another way
|
|
|
|
|
|
# Put everything you need into the data of the axes
|
|
|
self.data = {'xdata': xdata,
|
|
|
'ydata': ydata,
|
|
|
'xlabel': xlabel,
|
|
|
'ylabel': ylabel}
|
|
|
|
|
|
# Returning True or False is not optional
|
|
|
return(True)
|
|
|
class figMyFirstFigure(MyFig):
|
|
|
|
|
|
# The function where you declare the user-defined keywords
|
|
|
def declareKeywords(self):
|
|
|
|
|
|
# This function is the plotting procedure
|
|
|
def plotting(self):
|
|
|
# The size of the figure can be also defined here (optional)
|
|
|
self.FIGSIZE = (8., 6.) # the size are in inches. notes that a column in A&A is 8 inches.
|
|
|
|
|
|
# You can get the keywords you need from the figure
|
|
|
xrange = self.fig.keywords.get('xrange', None)
|
|
|
yrange = self.fig.keywords.get('yrange', None)
|
|
|
# the name of the dict is not optional.
|
|
|
self.keywords = {'<name of the keyword>': <default value>,
|
|
|
'xunit': 'years',
|
|
|
'withAnotation': False,
|
|
|
'twoColumn': False,
|
|
|
...}
|
|
|
|
|
|
# All matplotlib functions are available (see http://matplotlib.org/api/axes_api.html)
|
|
|
self.plot(self.data['xdata'], self.data['ydata'])
|
|
|
|
|
|
# Any decoration you need
|
|
|
self.set_xlabel(self.data['xlabel'])
|
|
|
self.set_ylabel(self.data['ylabel'])
|
|
|
# The function where you tell the figure where tu plot what
|
|
|
def addAxes(self):
|
|
|
|
|
|
if xrange is not None:
|
|
|
self.set_xlim(xrange)
|
|
|
# the aspect ratio of the axes and its position in the figure
|
|
|
ratioAxes1 = 6./8.
|
|
|
frameAxes1 = [0, 0, 0.5, 1.0] # [x0, y0, width, height] in unit of figwidth and figheight
|
|
|
|
|
|
if yrange is not None:
|
|
|
self.set_ylim(yrange)
|
|
|
ratioAxes2 = 6./8.
|
|
|
frameAxes2 = [0.5, 0.0, 0.5, 1.0]
|
|
|
|
|
|
# Returning True or False is not optional
|
|
|
return(True)
|
|
|
self.add_axes(AxMyFirstAxes(self, rationAxes1, frameAxes1))
|
|
|
self.add_axes(AxMyFirstAxes(self, rationAxes2, frameAxes2))
|
|
|
```
|
|
|
|
|
|
# Linking the new class to the module
|
... | ... | |