1.4.4. Graphiques¶
1.4.4.1. How to modify the plot parameters?¶
Edit the Matplotlib configuration file.
It is typically located here: ~/.matplotlib/matplotlibrc
.
For more information: http://matplotlib.sourceforge.net/users/customizing.html
1.4.4.2. My map takes time to draw¶
The map layouts that take time are those of a reduced area
which use a high resolution coastline (“f” from GSHHS or “s” for Histolitt from SHOM).
In the case of GSHHS traîts, a card caching system
plotted with mod:~mpl_toolkits.basemap is used
(see vacumm.misc.grid.basemap
):
if a map using the same zoom and resolution
must be traced, it is loaded from the cache.
For your information, cached maps are stored in the directory given by
the function get_map_dir()
(a priori
~/.matplotlib/basemap/cached_maps
).
Note
This cache system can generate errors during use of a saved card. See:user.faq.graphics.err_basemap.
In addition, a map may want to appear on the screen while you’re doing a remote plot, which can take time. If you want to disable this display, read : My figure is not displayed / turn off the display of figures like in batch mode.
1.4.4.3. How to tuner a graph to plot?¶
VACUMM’s graphical routines transfer keywords to most of the matplotlib functions used. We specify a keyword to transfer a prefixing this one of the name of the function suffixed with a”_” (use: func:~vacumm.misc.misc.kwfilter to filter keywords).
For example, it is possible to change the size of the title of a graph, and the thickness of the contours as follows:
>>> map2(sst, title_size=20, contour_linewidths=3)
In this specific case, to have the list of the other possible options
we refer to the documentation of functions matplotlib.pyplot.title()
and func:matplotlib.pyplot.contour.
In addition, Matplotlib plotted objects are often accessible using
the get_obj()
method that returns a list:
>>> m = map2((u, v), show=False)
>>> myquiver = m.get_obj('quiver')[0]
>>> mycontour = m.get_obj('contour')[0]
>>> myquiver.set_zorder(10)
>>> m.show()
Note you must set the show
parameter to False
if your
want to tune your plot (write mode), which is not necessary if you just
want to gather come parameters.
1.4.4.4. How to place a colorbar yourself?¶
Turn off the automatic colorbar plot and figure display, then draw it by specifying its position (cf. : func:matplotlib.pyplot.axes) :
m = map2(data, colorbar=False, right=.9, show=False) m.colorbar(cax=[.91, .2, .3, .6]) m.show()
or directly
map2(data, colorbar_cax==[.91, .2, .3, .6], right=.9, show=False)
See: func:matplotlib.pyplot.colorbar for plotting options.
1.4.4.5. My figure is not displayed / turn off the display of figures like in batch mode¶
The creation of figures requires the use of a graphical software layer.
These software layers are called backends. The minimum for the
saving the figures is to use the backend Agg
, this allows
also to bypass errors when using batch scripts
when the display is not available.
The other backends require a display, the TkAgg
backend
is almost systematically available.
The qt4agg backend is also available with UVCDAT.
If you want to make a display of your figures, use qt4agg
,
if you use Agg
, no display will be made.
There are two ways to modify the backend:
The permanent one consists in modifying the corresponding line in the Matplotlib configuration file:
backend : AggThe second way is to do it on the fly, at the beginning of a script (before any loading of
matplotlib
) andvacumm
):from matplotlib import use use('Agg')
1.4.4.6. How to disable automatic zoom?¶
For example when you draw a map with func:~vacumm.misc.plot.map2, if the unmasked data does not cover the entire domain, automatic zoom will avoid drawing areas that are not covered.
You can avoid this by using the xmasked=False
options,
symasked=False`, see xymasked=False
to disable zoom on both axes
(in the case of a 2D plot):
map(sst, xymasked=False)
1.4.4.7. How to add shadow or glow effects?¶
Most of the time, keywords are provided for this purpose for the plotting functions. For example, if you draw contours, you can do this to add a shadow to these and an effect glow to labels:
map2(data, contour_shadow=True, clabel_glow=True)
You can pass keywords to modify effects (see
add_shadow()
and add_glow()
to know the options):
map2(data, contour_shadow_width=4, contour_shadow_xoffset=3)
You can also proceed manually for an external trace:
m = map2(data, show=False)
m.add_shadow(m.axes.plot(x,y)) # m.axes.plot or pylab.plot
or:
from vacumm.misc.core_plot import add_shadow
add_shadow(P.plot(x,y))
1.4.4.8. I have an error with class Basemap
¶
It may be that the use of a map (typically when plotting with
map2()
) produces an error (for example a missing attribute,
such as celestial
or _mapboundarydrawn
).
This is probably related to the automatic caching of already drawn maps.
This process saves time when plotting a map with exactly the same
characteristics (domain, projection, coastline).
However, the cached card may not be compatible with the current version of
basemap
, following a python package update.
To solve the problem radically, you can delete all cached cards.
They are found by default in the directory given by the function
get_map_dir()
.
There is a function to perform this operation:
>>> from vacumm.misc.grid.basemap import reset_cache
>>> reset_cache()