fatiando.vis.mpl
)¶Wrappers for matplotlib
functions to facilitate plotting grids,
2D objects, etc.
This module loads all functions from matplotlib.pyplot
, adds new
functions and overwrites some others (like contour
,
pcolor
, etc).
Warning
This module will be removed in v0.6. We recommend the use of
matplotlib.pyplot
module directly. Some of the fatiando specific
functions will remain.
Grids
Grids are automatically reshaped and interpolated if desired or necessary.
2D objects
Interactive
Basemap (map projections)
Auxiliary
fatiando.vis.mpl.
basemap
(area, projection, resolution='c')[source]¶Make a basemap to use when plotting with map projections.
Uses the matplotlib basemap toolkit.
Parameters:
[west, east, south, north]
, i.e., the area of the data that is
going to be plotted
The name of the projection you want to use. Choose from:
The resolution for the coastlines. Can be ‘c’ for crude, ‘l’ for low, ‘i’ for intermediate, ‘h’ for high
Returns:
The basemap
fatiando.vis.mpl.
contour
(x, y, v, shape, levels, interp=False, extrapolate=False, color='k', label=None, clabel=True, style='solid', linewidth=1.0, basemap=None)[source]¶Make a contour plot of the data.
Parameters:
Arrays with the x and y coordinates of the grid points. If the data is on a regular grid, then assume x varies first (ie, inner loop), then y.
The scalar value assigned to the grid points.
Shape of the regular grid. If interpolation is not False, then will use shape to grid the data.
Number of contours to use or a list with the contour values.
Wether or not to interpolate before trying to plot. If data is not on regular grid, set to True!
Wether or not to extrapolate the data when interp=True
Color of the contour lines.
String with the label of the contour that would show in a legend.
Wether or not to print the numerical value of the contour lines
The style of the contour lines. Can be 'dashed'
, 'solid'
or
'mixed'
(solid lines for positive contours and dashed for negative)
Width of the contour lines
If not None, will use this basemap for plotting with a map projection
(see basemap
for creating basemaps)
Returns:
List with the values of the contour levels
fatiando.vis.mpl.
contourf
(x, y, v, shape, levels, interp=False, extrapolate=False, vmin=None, vmax=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, basemap=None)[source]¶Make a filled contour plot of the data.
Parameters:
Arrays with the x and y coordinates of the grid points. If the data is on a regular grid, then assume x varies first (ie, inner loop), then y.
The scalar value assigned to the grid points.
Shape of the regular grid. If interpolation is not False, then will use shape to grid the data.
Number of contours to use or a list with the contour values.
Wether or not to interpolate before trying to plot. If data is not on regular grid, set to True!
Wether or not to extrapolate the data when interp=True
Saturation values of the colorbar. If provided, will overwrite what is set by levels.
Color map to be used. (see pyplot.cm module)
If not None, will use this basemap for plotting with a map projection
(see basemap
for creating basemaps)
Returns:
List with the values of the contour levels
fatiando.vis.mpl.
draw_coastlines
(basemap, linewidth=1, style='solid')[source]¶Draw the coastlines using the given basemap.
Parameters:
The basemap used for plotting (see basemap
)
The width of the lines
The style of the lines. Can be: ‘solid’, ‘dashed’, ‘dashdot’ or ‘dotted’
fatiando.vis.mpl.
draw_countries
(basemap, linewidth=1, style='dashed')[source]¶Draw the country borders using the given basemap.
Parameters:
The basemap used for plotting (see basemap
)
The width of the lines
The style of the lines. Can be: ‘solid’, ‘dashed’, ‘dashdot’ or ‘dotted’
fatiando.vis.mpl.
draw_geolines
(area, dlon, dlat, basemap, linewidth=1)[source]¶Draw the parallels and meridians on a basemap plot.
Parameters:
[west, east, south, north]
, i.e., the area where the lines will
be plotted
The spacing between the lines in the longitude and latitude directions, respectively (in decimal degrees)
The basemap used for plotting (see basemap
)
The width of the lines
fatiando.vis.mpl.
draw_layers
(area, axes, style='-', marker='o', color='k', width=2)[source]¶Draw series of horizontal layers by clicking with the mouse.
The y-axis is assumed to be depth, the x-axis is the physical property of each layer.
INSTRUCTIONS:
Parameters:
Borders of the area containing the polygon
The figure to use for drawing the polygon. To get an Axes instace, just do:
from matplotlib import pyplot
axes = pyplot.figure().add_subplot(1,1,1)
You can plot things to axes
before calling this function so that
they’ll appear on the background.
Line style (as in matplotlib.pyplot.plot)
Style of the point markers (as in matplotlib.pyplot.plot)
Line color (as in matplotlib.pyplot.plot)
The line width (as in matplotlib.pyplot.plot)
Returns:
layers : list = [thickness, values]
- thickness
: listThe thickness of each layer, in order of increasing depth
- values
: listThe physical property value of each layer, in the same order
fatiando.vis.mpl.
draw_polygon
(area, axes, style='-', marker='o', color='k', width=2, alpha=0.5, xy2ne=False)[source]¶Draw a polygon by clicking with the mouse.
INSTRUCTIONS:
Parameters:
Borders of the area containing the polygon
The figure to use for drawing the polygon. To get an Axes instace, just do:
from matplotlib import pyplot
axes = pyplot.figure().add_subplot(1,1,1)
You can plot things to axes
before calling this function so that
they’ll appear on the background.
Line style (as in matplotlib.pyplot.plot)
Style of the point markers (as in matplotlib.pyplot.plot)
Line color (as in matplotlib.pyplot.plot)
The line width (as in matplotlib.pyplot.plot)
Transparency of the fill of the polygon. 0 for transparent, 1 for opaque (fills the polygon once done drawing)
If True, will exchange the x and y axis so that x points north.
Use this when drawing on a map viewed from above. If the y-axis of the
plot is supposed to be z (depth), then use xy2ne=False
.
Returns:
List of [x, y]
pairs with the edges of the polygon
fatiando.vis.mpl.
layers
(thickness, values, style='-k', z0=0.0, linewidth=1, label=None, **kwargs)[source]¶Plot a series of layers and values associated to each layer.
Parameters:
The thickness of each layer in order of increasing depth
The value associated with each layer in order of increasing depth
String with the color and line style (as in matplotlib.pyplot.plot)
The depth of the top of the first layer
Line width
label associated with the square.
Returns:
matplitlib.axes
The axes element of the plot
fatiando.vis.mpl.
m2km
(axis=None)[source]¶Convert the x and y tick labels from meters to kilometers.
Parameters:
The plot.
Tip
Use fatiando.vis.gca()
to get the current axis. Or the value
returned by fatiando.vis.subplot
or matplotlib.pyplot.subplot
.
fatiando.vis.mpl.
paths
(pts1, pts2, style='-k', linewidth=1, label=None)[source]¶Plot paths between the two sets of points.
Parameters:
List of (x, y) pairs with the coordinates of the points
List of (x, y) pairs with the coordinates of the points
String with the color and line style (as in matplotlib.pyplot.plot)
The width of the lines representing the paths
If not None, then the string that will show in the legend
fatiando.vis.mpl.
pcolor
(x, y, v, shape, interp=False, extrapolate=False, cmap=<matplotlib.colors.LinearSegmentedColormap object>, vmin=None, vmax=None, basemap=None)[source]¶Make a pseudo-color plot of the data.
Parameters:
Arrays with the x and y coordinates of the grid points. If the data is on a regular grid, then assume x varies first (ie, inner loop), then y.
The scalar value assigned to the grid points.
Shape of the regular grid. If interpolation is not False, then will use shape to grid the data.
Wether or not to interpolate before trying to plot. If data is not on regular grid, set to True!
Wether or not to extrapolate the data when interp=True
Color map to be used. (see pyplot.cm module)
Saturation values of the colorbar.
If not None, will use this basemap for plotting with a map projection
(see basemap
for creating basemaps)
Returns:
matplitlib.axes
The axes element of the plot
fatiando.vis.mpl.
pick_points
(area, axes, marker='o', color='k', size=8, xy2ne=False)[source]¶Get the coordinates of points by clicking with the mouse.
INSTRUCTIONS:
Parameters:
Borders of the area containing the points
The figure to use for drawing the polygon. To get an Axes instace, just do:
from matplotlib import pyplot
axes = pyplot.figure().add_subplot(1,1,1)
You can plot things to axes
before calling this function so that
they’ll appear on the background.
Style of the point markers (as in matplotlib.pyplot.plot)
Line color (as in matplotlib.pyplot.plot)
Marker size (as in matplotlib.pyplot.plot)
If True, will exchange the x and y axis so that x points north.
Use this when drawing on a map viewed from above. If the y-axis of the
plot is supposed to be z (depth), then use xy2ne=False
.
Returns:
List of [x, y]
coordinates of the points
fatiando.vis.mpl.
points
(pts, style='.k', size=10, label=None, xy2ne=False)[source]¶Plot a list of points.
Parameters:
List of [x, y] pairs with the coordinates of the points
String with the color and line style (as in matplotlib.pyplot.plot)
Size of the plotted points
If not None, then the string that will show in the legend
If True, will exchange the x and y axis so that the x coordinates of
the polygon are north. Use this when drawing on a map viewed from
above. If the y-axis of the plot is supposed to be z (depth), then use
xy2ne=False
.
Returns:
matplitlib.axes
The axes element of the plot
fatiando.vis.mpl.
polygon
(polygon, style='-k', linewidth=1, fill=None, alpha=1.0, label=None, xy2ne=False, linealpha=1.0)[source]¶Plot a polygon.
Parameters:
fatiando.mesher.Polygon
The polygon
Color and line style string (as in matplotlib.pyplot.plot)
Line width
A color string used to fill the polygon. If None, the polygon is not filled
Transparency of the fill (1 >= alpha >= 0). 0 is transparent and 1 is opaque
Transparency of the line (1 >= alpha >= 0). 0 is transparent and 1 is opaque
String with the label identifying the polygon in the legend
If True, will exchange the x and y axis so that the x coordinates of
the polygon are north. Use this when drawing on a map viewed from
above. If the y-axis of the plot is supposed to be z (depth), then use
xy2ne=False
.
Returns:
Line corresponding to the polygon plotted
fatiando.vis.mpl.
seismic_image
(section, dt=0.004, ranges=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>, aspect=None, vmin=None, vmax=None)[source]¶Plot a seismic section (numpy 2D array matrix) as an image.
Parameters:
matrix of traces (first dimension time, second dimension traces)
sample rate in seconds (default 4 ms)
min and max horizontal values (default trace number)
color map to be used. (see pyplot.cm module)
matplotlib imshow aspect parameter, ratio between axes
min and max values for imshow
fatiando.vis.mpl.
seismic_wiggle
(section, dt=0.004, ranges=None, scale=1.0, color='k', normalize=False)[source]¶Plot a seismic section (numpy 2D array matrix) as wiggles.
Parameters:
matrix of traces (first dimension time, second dimension traces)
sample rate in seconds (default 4 ms)
min and max horizontal values (default trace number)
scale factor multiplied by the section values before plotting
Color for filling the wiggle, positive and negative lobes.
True to normalizes all trace in the section using global max/min data will be in the range (-0.5, 0.5) zero centered
Warning
Slow for more than 200 traces, in this case decimate your
data or use seismic_image
.
fatiando.vis.mpl.
set_area
(area)[source]¶Set the area of a Matplolib plot using xlim and ylim.
Parameters:
Coordinates of the top right and bottom left corners of the area
fatiando.vis.mpl.
square
(area, style='-k', linewidth=1, fill=None, alpha=1.0, label=None, xy2ne=False)[source]¶Plot a square.
Parameters:
Borders of the square
String with the color and line style (as in matplotlib.pyplot.plot)
Line width
A color string used to fill the square. If None, the square is not filled
Transparency of the fill (1 >= alpha >= 0). 0 is transparent and 1 is opaque
label associated with the square.
If True, will exchange the x and y axis so that the x coordinates of
the polygon are north. Use this when drawing on a map viewed from
above. If the y-axis of the plot is supposed to be z (depth), then use
xy2ne=False
.
Returns:
matplitlib.axes
The axes element of the plot
fatiando.vis.mpl.
squaremesh
(mesh, prop, cmap=<matplotlib.colors.LinearSegmentedColormap object>, vmin=None, vmax=None)[source]¶Make a pseudo-color plot of a mesh of squares
Parameters:
fatiando.mesher.SquareMesh
or compatibleThe mesh (a compatible mesh must implement the methods get_xs
and
get_ys
)
The physical property of the squares to use as the color scale.
Color map to be used. (see pyplot.cm module)
Saturation values of the colorbar.
Returns:
matplitlib.axes
The axes element of the plot