Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix plot_2d color fill #187

Merged
merged 3 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://pypi.python.org/pypi/pytest-mpl/0.3
"""
import pytest
import matplotlib.pyplot as plt

from welly import Well
from welly import Project
Expand Down Expand Up @@ -75,7 +74,16 @@ def test_curve_2d_plot(well):
"""
Tests mpl image of curve as VD display.
"""
fig = well.data['GR'].plot_2d().get_figure()
curve = well.data['GR']

# plot 2D curve
curve.plot_2d()

# subtract curve values from 200
curve2 = 200-curve

# plot a curve with clipped colored mask
fig = curve2.plot_2d(cmap='viridis', curve=True, lw=-.5, edgecolor='k').get_figure()

return fig

Expand All @@ -86,8 +94,8 @@ def test_synthetic_plot():
Tests mpl image of synthetic.
"""
data = [4, 2, 0, -4, -2, 1, 3, 6, 3, 1, -2, -5, -1, 0]
params = {'dt': 0.004}
s = Synthetic(data, params=params)
test_params = {'dt': 0.004}
s = Synthetic(data, params=test_params)

fig = s.plot().get_figure()

Expand Down
4 changes: 2 additions & 2 deletions welly/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self,
run=None,
service_company=None,
units=None,
family=None):
log_type=None):

if isinstance(mnemonic, str):
mnemonic = [mnemonic]
Expand All @@ -98,7 +98,7 @@ def __init__(self,
self.code = code
self.description = description
self.units = units
self.family = family
self.log_type = log_type
# set parameters related to well
self.api = api
self.date = date
Expand Down
11 changes: 7 additions & 4 deletions welly/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,23 @@ def plot_2d_curve(curve,
raise NotImplementedError("Can only handle up to 3 dimensions.")

# At this point, a is either a 2D array, or a 2D (rgb) array.
extent = [0, width or default, curve.stop, curve.start]
extent = [min(curve_data) or 0, max(curve_data) or default, curve.stop, curve.start]
im = ax.imshow(a, cmap=cmap, extent=extent, aspect='auto')

if plot_curve:
paths = ax.fill_betweenx(curve.basis, curve_data, np.nanmin(curve_data),
paths = ax.fill_betweenx(y=curve.basis,
x1=curve_data,
x2=np.nanmin(curve_data),
facecolor='none',
**kwargs)

# Make the 'fill' mask and clip the background image with it.
patch = PathPatch(paths._paths[0], visible=False)
ax.add_artist(patch)
im.set_clip_path(patch)

ax.set_xticks([])
else:
# if not plotting a curve, the x-axis is dimensionless
ax.set_xticks([])

# Rely on interval order.
lower, upper = curve.stop, curve.start
Expand Down