plot
¶
Utility functions and defintions for a common plot style throughout Pyrocko.
Functions with name prefix mpl_
are Matplotlib specific. All others should
be toolkit-agnostic.
The following skeleton can be used to produce nice PDF figures, with absolute
sizes derived from paper and font sizes
(file /../../examples/plot_skeleton.py
in the Pyrocko source directory):
from matplotlib import pyplot as plt
from pyrocko.plot import mpl_init, mpl_margins, mpl_papersize
# from pyrocko.plot import mpl_labelspace
fontsize = 9. # in points
# set some Pyrocko style defaults
mpl_init(fontsize=fontsize)
fig = plt.figure(figsize=mpl_papersize('a4', 'landscape'))
# let margins be proportional to selected font size, e.g. top and bottom
# margin are set to be 5*fontsize = 45 [points]
labelpos = mpl_margins(fig, w=7., h=5., units=fontsize)
axes = fig.add_subplot(1, 1, 1)
# positioning of axis labels
# mpl_labelspace(axes) # either: relative to axis tick labels
labelpos(axes, 2., 1.5) # or: relative to left/bottom paper edge
axes.plot([0, 1], [0, 9])
axes.set_xlabel('Time [s]')
axes.set_ylabel('Amplitude [m]')
fig.savefig('plot_skeleton.pdf')
plt.show()
# Pyrocko plot Module
pyrocko.plot.automap
Quickly generate pretty maps using gmtpy’s powers.pyrocko.plot.beachball
Beachball visualisation for matplotlib.pyrocko.plot.cake_plot
Plotting velocities models and ray paths.pyrocko.plot.hudson
Generate hudson plots with this module.pyrocko.plot.response
Plot the station’s response’s.
GMTPy
pyrocko.plot.gmtpy
With support for GMT5 pyrocko’s gmtpy exposes GMT’s neat mapping functions to Python 2/3.
- papersize(paper, orientation='landscape', units='point')[source]¶
Get paper size from string.
- Parameters
paper – string selecting paper size. Choices:
'a0'
,'a1'
,'a2'
,'a3'
,'a4'
,'a5'
,'a6'
,'a7'
,'a8'
,'a9'
,'a10'
,'b0'
,'b1'
,'b2'
,'b3'
,'b4'
,'b5'
,'archa'
,'archb'
,'archc'
,'archd'
,'arche'
,'flsa'
,'halfletter'
,'note'
,'letter'
,'legal'
,'11x17'
,'ledger'
orientation –
'landscape'
, or'portrait'
units – Units to be returned. Choices:
'point'
,'inch'
, or'cm'
- Returns
(width, height)
- class AutoScaleMode(...) dummy for str [source]¶
Mode of operation for auto-scaling.
mode
description
'auto'
:Look at data range and choose one of the choices below.
'min-max'
:Output range is selected to include data range.
'0-max'
:Output range shall start at zero and end at data max.
'min-0'
:Output range shall start at data min and end at zero.
'symmetric'
:Output range shall by symmetric by zero.
'off'
:Similar to
'min-max'
, but snap and space are disabled, such that the output range always exactly matches the data range.
- class AutoScaler(approx_ticks=7.0, mode='auto', exp=None, snap=False, inc=None, space=0.0, exp_factor=3, no_exp_interval=(- 3, 5))[source]¶
Tunable 1D autoscaling based on data range.
Instances of this class may be used to determine nice minima, maxima and increments for ax annotations, as well as suitable common exponents for notation.
The autoscaling process is guided by the following public attributes:
- ♦ approx_ticks¶
float
, default:7.0
Approximate number of increment steps (tickmarks) to generate.
- ♦ mode¶
str
(AutoScaleMode
), default:'auto'
Mode of operation for auto-scaling.
- ♦ exp¶
int
, optionalIf defined, override automatically determined exponent for notation by the given value.
- ♦ snap¶
bool
, default:False
If set to True, snap output range to multiples of increment. This parameter has no effect, if mode is set to
'off'
.
- ♦ inc¶
float
, optionalIf defined, override automatically determined tick increment by the given value.
- ♦ space¶
float
, default:0.0
Add some padding to the range. The value given, is the fraction by which the output range is increased on each side. If mode is
'0-max'
or'min-0'
, the end at zero is kept fixed at zero. This parameter has no effect if mode is set to'off'
.
- ♦ exp_factor¶
int
, default:3
Exponent of notation is chosen to be a multiple of this value.
- ♦ no_exp_interval¶
tuple
of 2int
objects, default:(-3, 5)
Range of exponent, for which no exponential notation is aallowed.
- make_scale(data_range, override_mode=None)[source]¶
Get nice minimum, maximum and increment for given data range.
Returns
(minimum, maximum, increment)
or(maximum, minimum, -increment)
, depending on whether data_range is(data_min, data_max)
or(data_max, data_min)
. Ifoverride_mode
is defined, the mode attribute is temporarily overridden by the given value.
- mpl_init(fontsize=10)[source]¶
Initialize Matplotlib rc parameters Pyrocko style.
Returns the matplotlib.pyplot module for convenience.
- mpl_margins(fig, left=1.0, top=1.0, right=1.0, bottom=1.0, wspace=None, hspace=None, w=None, h=None, nw=None, nh=None, all=None, units='inch')[source]¶
Adjust Matplotlib subplot params with absolute values in user units.
Calls
matplotlib.figure.Figure.subplots_adjust()
onfig
with absolute margin widths/heights rather than relative values. Ifwspace
orhspace
are given, the number of subplots must be given innw
andnh
becausesubplots_adjust()
treats the spacing parameters relative to the subplot width and height.- Parameters
units – Unit multiplier or unit as string:
'point'
,'inch'
, or'cm'
left,right,top,bottom – margin space
w – set
left
andright
at onceh – set
top
andbottom
at onceall – set
left
,top
,right
, andbottom
at oncenw – number of subplots horizontally
nh – number of subplots vertically
wspace – horizontal spacing between subplots
hspace – vertical spacing between subplots
- mpl_papersize(paper, orientation='landscape')[source]¶
Get paper size in inch from string.
Returns argument suitable to be passed to the
figsize
argument ofpyplot.figure()
.- Parameters
paper – string selecting paper size. Choices:
'a0'
,'a1'
,'a2'
,'a3'
,'a4'
,'a5'
,'a6'
,'a7'
,'a8'
,'a9'
,'a10'
,'b0'
,'b1'
,'b2'
,'b3'
,'b4'
,'b5'
,'archa'
,'archb'
,'archc'
,'archd'
,'arche'
,'flsa'
,'halfletter'
,'note'
,'letter'
,'legal'
,'11x17'
,'ledger'
orientation –
'landscape'
, or'portrait'
- Returns
(width, height)
- mpl_color(x)[source]¶
Convert string into color float tuple ranged 0-1 for use with Matplotlib.
Accepts tango color names, matplotlib color names, and slash-separated strings. In the latter case, if values are larger than 1., the color is interpreted as 0-255 ranged. Single-valued (grayscale), three-valued (color) and four-valued (color with alpha) are accepted. An
InvalidColorDef
exception is raised when the convertion fails.
- mpl_time_axis(axes, approx_ticks=5.0)[source]¶
Configure x axis of a matplotlib axes object for interactive time display.
- Parameters
axes (
matplotlib.axes.Axes
) – Axes to be configured.approx_ticks (float) – Approximate number of ticks to create.
This function tries to use nice tick increments and tick labels for time ranges from microseconds to years, similar to how this is handled in Snuffler.