-
Notifications
You must be signed in to change notification settings - Fork 7
/
mpwell.py
78 lines (71 loc) · 3.41 KB
/
mpwell.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/env python
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
default_color='C0'
def mpwell(tracks, title=None, mindepth=None, maxdepth=None, tagged_depths=None):
"""Create a well log using matplotlib.
tracks: list of tracks. Each track is a dictionary with a 'traces'
key (required), and possibly keys that describe the scale (log or linear)
and appearance of the track. The 'traces' key points to a list of traces.
Each trace is a dictionary containing a 'data' key that points to a Pandas
DataFrame that contains the data to be plotted. The DataFrame must have
a column named 'depth' that contains the depth in the desired units, and
also a column named the same as value of the 'curve' key in the trace. The
trace dictionary may also have a 'label' key that provides the log mnemonic
for the trace, and additional keys that describe the appearance of the trace.
title: Display title for the log.
mindepth: minimum depth to be plotted. Optional. Determined from the first trace
of the first track, if not specified.
maxdepth: maximum depth to be plotted. Optional. Determined from the first trace
of the first track, if not specified.
tagged_depths: List of depths which should be marked on the logs with a horizontal
line.
"""
f, axs = plt.subplots(nrows=1, ncols=len(tracks), figsize=(8, 10))
if title:
f.suptitle(title, fontsize=22)
# reserve space at the top and between subplots
f.subplots_adjust(top=.85,wspace=0.25)
first_trace_data = tracks[0]['traces'][0]['data']
if mindepth is None:
mindepth = min(first_trace_data['depth'])
if maxdepth is None:
maxdepth = max(first_trace_data['depth'])
# set up each track
for ax in axs:
ax.set_ylim(mindepth,maxdepth)
ax.invert_yaxis()
ax.get_xaxis().set_visible(False)
# plot each trace in each track
for num_track, track in enumerate(tracks):
for i, trace in enumerate(track['traces']):
color = trace.get('color', default_color)
label = trace.get('label', trace['curve'])
ls = trace.get('ls', '-')
marker = trace.get('marker', 'None')
axi = axs[num_track].twiny()
axi.set_xlim(*trace['range'])
axi.set_ylim(mindepth, maxdepth)
axi.spines['top'].set_position(('outward', 5+30*i))
axi.spines['top'].set_color(color)
axi.xaxis.set_ticks(trace['range'])
axi.set_xlabel(label, color=color, labelpad=-5)
axi.plot(trace['data'][trace['curve']], trace['data']['depth'],
ls=ls, marker=marker, color=color)
if 'xref' in trace:
axi.axvline(trace['xref'], color='k', linestyle='--')
axi.tick_params(axis='x', colors=color, length=0)
axi.yaxis.grid(False)
axi.invert_yaxis()
if tagged_depths is not None:
for depth in tagged_depths:
axi.axhline(depth, color='grey', lw=1)
if num_track>0:
axi.set_yticklabels([])
else:
# Turn off the "offset" in the y-axis labeling
y_formatter = mpl.ticker.ScalarFormatter(useOffset=False)
axi.yaxis.set_major_formatter(y_formatter)
axs[0].set_ylabel('depth (m)')
return f