├── .gitignore ├── LICENSE ├── README.md ├── example.png └── mpwell.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Grant Goodyear 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # matplot-well-log 2 | Simple well log plotting using Python and matplotlib 3 | 4 | Right now there is just an mpwell function that gets called. At some point, 5 | I should really refactor this code so that there are Trace and Track 6 | objects 7 | 8 | ```python 9 | from mpwell import mpwell 10 | 11 | trace11 = {'data': dfB, 'curve': 'GR', 'range': (0, 250)} 12 | track1 = {'traces': [trace11]} 13 | trace21 = {'data': dfB, 'curve': 'RHOB', 'range': (1.5, 3.0)} 14 | track2 = {'traces': [trace21]} 15 | trace31 = {'data': dfB, 'curve': 'PHID', 'label': 'SS PHID', 'color': 'c', 'range': (0, 0.40)} 16 | trace32 = {'data': dfB, 'curve': 'PHIN', 'label': 'SS PHIN', 'range': (0, 0.40)} 17 | track3 = {'traces': [trace31, trace32]} 18 | trace41 = {'data': xrd3df, 'curve': 'total_clay', 'label': 'Percent Clay', 'ls': 'None', 'marker':'o', 'range': (0, 60)} 19 | track4 = {'traces': [trace41]} 20 | tracks = [track1, track2, track3, track4] 21 | xrd_depths = xrd3df['depth'] 22 | log = mpwell(tracks, 'My well', min(xrd_depths), max(xrd_depths), xrd3df['depth']) 23 | ``` 24 | 25 | ![example log](example.png) 26 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g2boojum/matplot-well-log/e6f35bedd0f7cfd226fbbd2a677cd60f2a2d4122/example.png -------------------------------------------------------------------------------- /mpwell.py: -------------------------------------------------------------------------------- 1 | #! /bin/env python 2 | 3 | import numpy as np 4 | import matplotlib as mpl 5 | import matplotlib.pyplot as plt 6 | 7 | default_color='C0' 8 | def mpwell(tracks, title=None, mindepth=None, maxdepth=None, tagged_depths=None): 9 | """Create a well log using matplotlib. 10 | 11 | tracks: list of tracks. Each track is a dictionary with a 'traces' 12 | key (required), and possibly keys that describe the scale (log or linear) 13 | and appearance of the track. The 'traces' key points to a list of traces. 14 | Each trace is a dictionary containing a 'data' key that points to a Pandas 15 | DataFrame that contains the data to be plotted. The DataFrame must have 16 | a column named 'depth' that contains the depth in the desired units, and 17 | also a column named the same as value of the 'curve' key in the trace. The 18 | trace dictionary may also have a 'label' key that provides the log mnemonic 19 | for the trace, and additional keys that describe the appearance of the trace. 20 | 21 | title: Display title for the log. 22 | 23 | mindepth: minimum depth to be plotted. Optional. Determined from the first trace 24 | of the first track, if not specified. 25 | 26 | maxdepth: maximum depth to be plotted. Optional. Determined from the first trace 27 | of the first track, if not specified. 28 | 29 | tagged_depths: List of depths which should be marked on the logs with a horizontal 30 | line. 31 | """ 32 | f, axs = plt.subplots(nrows=1, ncols=len(tracks), figsize=(8, 10)) 33 | if title: 34 | f.suptitle(title, fontsize=22) 35 | # reserve space at the top and between subplots 36 | f.subplots_adjust(top=.85,wspace=0.25) 37 | first_trace_data = tracks[0]['traces'][0]['data'] 38 | if mindepth is None: 39 | mindepth = min(first_trace_data['depth']) 40 | if maxdepth is None: 41 | maxdepth = max(first_trace_data['depth']) 42 | # set up each track 43 | for ax in axs: 44 | ax.set_ylim(mindepth,maxdepth) 45 | ax.invert_yaxis() 46 | ax.get_xaxis().set_visible(False) 47 | # plot each trace in each track 48 | for num_track, track in enumerate(tracks): 49 | for i, trace in enumerate(track['traces']): 50 | color = trace.get('color', default_color) 51 | label = trace.get('label', trace['curve']) 52 | ls = trace.get('ls', '-') 53 | marker = trace.get('marker', 'None') 54 | axi = axs[num_track].twiny() 55 | axi.set_xlim(*trace['range']) 56 | axi.set_ylim(mindepth, maxdepth) 57 | axi.spines['top'].set_position(('outward', 5+30*i)) 58 | axi.spines['top'].set_color(color) 59 | axi.xaxis.set_ticks(trace['range']) 60 | axi.set_xlabel(label, color=color, labelpad=-5) 61 | axi.plot(trace['data'][trace['curve']], trace['data']['depth'], 62 | ls=ls, marker=marker, color=color) 63 | if 'xref' in trace: 64 | axi.axvline(trace['xref'], color='k', linestyle='--') 65 | axi.tick_params(axis='x', colors=color, length=0) 66 | axi.yaxis.grid(False) 67 | axi.invert_yaxis() 68 | if tagged_depths is not None: 69 | for depth in tagged_depths: 70 | axi.axhline(depth, color='grey', lw=1) 71 | if num_track>0: 72 | axi.set_yticklabels([]) 73 | else: 74 | # Turn off the "offset" in the y-axis labeling 75 | y_formatter = mpl.ticker.ScalarFormatter(useOffset=False) 76 | axi.yaxis.set_major_formatter(y_formatter) 77 | axs[0].set_ylabel('depth (m)') 78 | return f 79 | --------------------------------------------------------------------------------