agilescientific / geotransect

Tool for summarizing data available along 2D transects.
Apache License 2.0
9 stars 4 forks source link

Update with striplog figures #10

Open EvanBianco opened 9 years ago

EvanBianco commented 9 years ago

The most recent implementations of Striplog allows one to return the figure from striplog.plot(). If we can get the axes for the stiplog figure, then we can sculpt is using PathPatches. This will make drawing the feature plot faster, it will also allow easier overlay of the striplog on cross-sections.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import PathPatch

x = np.random.normal(0, 1, 1000).cumsum()
x -= x.min()
y = np.arange(x.size)

fig = plt.figure(figsize=(4, 10))
ax = fig.add_subplot(111)
bgim = ax.imshow(np.random.rand(y.max(), x.max()), cmap='Greys', 
                 extent=[-10, 50, 0, 1000])
im = ax.imshow(x[:, None], extent=[x.min(), x.max(), y.min(), y.max()],
               cmap='gist_earth', aspect='auto', origin='lower')
paths = ax.fill_betweenx(y, x, facecolor='none')
patch = PathPatch(paths._paths[0], visible=False)
ax.add_artist(patch)
im.set_clip_path(patch)
ax.invert_yaxis()
plt.show()

image

kwinkunks commented 9 years ago

Very cool. To clarify: you see this replacing the existing method or drawing patches?

It seems like there could be a problem with interpolation — just like with the usual way to paint lithologies on curves using a colourmap, at most resolutions, you end up with colours between the discrete colours, when in fact you want it to change abruptly.

I guess it is possible to paint/fill with a different curve? How would the striplog data (say, lithologies) have to look to paint with that? Would it have to be a curve, essentially? Can we pain with arbitrary (i.e. legend) colours, or would we have to make a fake colourmap that maps to the legend?

EvanBianco commented 9 years ago

I propose that this is a better way to draw logs using patches. Yes I think we can paint with arbitrary colours. It's really a better way of sculpting a striplog with a log (like we do in the feature plot of geotransect). Instead of creating a white mask over an image, we are creating a clipped path (defined by a log curve) around an image (which we may want to be a striplog, but can be any image), which allows it to be inserted on top of other stuff (on a seismic image say).

To be clear, the color-filled image can be anything we want (just as before), and we can use clip it using any log (it could be the striplog variable width, or it could be a fixed width "bar".

In this example, I am "painting" with an entirely different set of data than the log. I'll work up an example with an actual striplog.

It does potentially mean re-writing the striplog.plot() method, to handle option keyword arguments for logs to sculpt with say.

In the code snippet above, we are doing clip_path, on im which is an axes object, so that might be the thing we need to return striplog.plot(), or perhaps it needs some other method?

im.set_clip_path(patch)

image

BTW: this method / trick was shared by Joe K.