0

I have a vertical line plot of Lithology data (x=Lithology, y=Depth) and a dictionary with colors and patterns. I need to fill my line plot using plotly and patterns:colors from my dictionary, like one in this picture on the right side. In matplotlib this achieved with ax.fill_betweenx().

ax.fill_betweenx(well['DEPTH_MD'], 0, well['LITHOLOGY'], 
                      where=(well['LITHOLOGY']==key),
                      facecolor=color, hatch=hatch)

How can it be done in plotly?

Well Logs

1 Answers1

0

A workaround:

import numpy as np
import plotly.graph_objects as go

depth = list(range(2900, 3100, 5))
density1 = np.random.random_sample((len(depth), )) * 2
density2 = np.random.random_sample((len(depth), )) * 2 + 1


fig = go.Figure()

fig.add_trace(go.Scatter(
    x=density1, 
    y=depth, 
    mode='lines',
    name='left'
))

fig.add_trace(go.Scatter(
    x=density2, 
    y=depth, 
    mode='lines',
    name='right'
))

fig.for_each_trace(
    lambda trace: trace.update(fill='tonextx') if trace.name == "right" else (),
)

fig.show()

My solution requires you to give a name to each trace (ie. lines). Only after the two traces are updated, do fig.for_each_trace() to update either one of the traces with argument fill='tonextx'.

tyson.wu
  • 704
  • 5
  • 7