Creating geological plots in plotly

Hello! I would like to recreate a matplotlib plot displaying geological lithology data in plotly.
In matplotlib it can be done with this code (I guess the key point is fill_betweenx() method).
How can it be done in plotly?

lithology_numbers = {30000: {'lith':'Sandstone', 'lith_num':1, 'hatch': '..', 'color':'#ffff00'},
                 65030: {'lith':'Sandstone/Shale', 'lith_num':2, 'hatch':'-.', 'color':'#ffe119'},
                 65000: {'lith':'Shale', 'lith_num':3, 'hatch':'--', 'color':'#bebebe'},
                 80000: {'lith':'Marl', 'lith_num':4, 'hatch':'', 'color':'#7cfc00'},
                 74000: {'lith':'Dolomite', 'lith_num':5, 'hatch':'-/', 'color':'#8080ff'},
                 70000: {'lith':'Limestone', 'lith_num':6, 'hatch':'+', 'color':'#80ffff'},
                 70032: {'lith':'Chalk', 'lith_num':7, 'hatch':'..', 'color':'#80ffff'},
                 88000: {'lith':'Halite', 'lith_num':8, 'hatch':'x', 'color':'#7ddfbe'},
                 86000: {'lith':'Anhydrite', 'lith_num':9, 'hatch':'', 'color':'#ff80ff'},
                 99000: {'lith':'Tuff', 'lith_num':10, 'hatch':'||', 'color':'#ff8c00'},
                 90000: {'lith':'Coal', 'lith_num':11, 'hatch':'', 'color':'black'},
                 93000: {'lith':'Basement', 'lith_num':12, 'hatch':'-|', 'color':'#ef138a'}}

    fig, ax = plt.subplots(figsize=(15,10))

    # Lithology track
    ax.plot(well["LITHOLOGY"], well['DEPTH_MD'], color = "black", linewidth = 0.5)
    ax.set_xlabel("Lithology")
    ax.set_xlim(0, 1)
    ax.xaxis.label.set_color("black")
    ax.tick_params(axis='x', colors="black")
    ax.spines["top"].set_edgecolor("black")

    for key in lithology_numbers.keys():
        color = lithology_numbers[key]['color']
        hatch = lithology_numbers[key]['hatch']
        ax.fill_betweenx(well['DEPTH_MD'], 0, well['LITHOLOGY'], where=(well['LITHOLOGY']==key),
                         facecolor=color, hatch=hatch)

Untitled

Hey @hikkers ,

You can use bar charts.

I did something like that for a geothermal well.

Have a nice day.

Hi @akroma ,

Your plot looks great. I’m also looking for a solution to this problem. Do you want to share some code examples of how you did it?

Hey @martindyring ,

Welcome to the community.

I’ll share an example in few days.

Have a nice day.

@martindyring

import pandas as pd
import numpy as np
import plotly.graph_objects as go

fig = go.Figure()

lithology = pd.read_csv('sample_litho.txt')
lithology['constant'] = 0 

data_length = len(lithology)
counter = data_length - 1

max_depth = min(lithology['depth'])
z_axis_depth = max_depth - 10

for i in range(data_length):

            if i + 1 <= counter:
                
                name = lithology.loc[i+1, "unit"]
                clr = lithology.loc[i+1, "color"]
                z1 = [lithology.loc[i, "depth"]]
                z2 = [lithology.loc[i+1, "depth"] - lithology.loc[i, "depth"]]
                z3 = [lithology.loc[i, "depth"]]

                fig.add_trace(go.Bar(name=name,
                                     marker=dict(color=clr),
                                     x=lithology['constant'],y=z2,
                                     base=z3,
                                     offsetgroup=0,
                                     showlegend=False
                                     )
                              )

              
                fig.update_yaxes(range=[z_axis_depth, 0])
                fig.update_xaxes(range=[-0.5,0.5])

fig.show()

Sample Data:

depth,unit,color
0,Kiltaşı,green
-50,Kiltaşı,green
-470,Kumtaşı,yellow
-490,Kiltaşı,green
-550,Kumtaşı,yellow
-590,Kiltaşı,green
-650,Kumtaşı,yellow
-690,Kiltaşı,green
-720,Kumtaşı,yellow
-740,Kiltaşı,green
-810,Kumtaşı,yellow
-830,Kömür,black
-1010,Kumtaşı,yellow
-1050,Kiltaşı,green
-1170,Kumtaşı,yellow
-1190,Kiltaşı,green
-1270,Kumtaşı,yellow
-1300,Kiltaşı,green
-1360,Kumtaşı,yellow
-1400,Kiltaşı,green
-1420,Kumtaşı,yellow
-1500,Kiltaşı,green
-1510,Kumtaşı,yellow
-1590,Kiltaşı,green
-1600,Kumtaşı,yellow
-1690,Kiltaşı,green
-1700,Kumtaşı,yellow
-1740,Kiltaşı,green
-1820,Kumtaşı,yellow
-1920,Kuvars-şist,purple
-1950,Mika-şist,grey
-1990,Kuvars-şist,purple
-2040,Siyah-şist,darkgrey
-2070,Kuvars-şist,purple
-2100,Siyah-şist,darkgrey
-2130,Mermer,blue
-2160,Siyah-şist,darkgrey
-2190,Kuvars-şist,purple
-2210,Siyah-şist,darkgrey
-2230,Mermer,blue
-2320,Kuvars-şist,purple
-2340,Siyah-şist,darkgrey
-2510,Kuvars-şist,purple
-2550,Siyah-şist,darkgrey
-2610,Kuvars-şist,purple
-2650,Siyah-şist,darkgrey
-2720,Mermer,blue
-2740,Kuvars-şist,purple
-2900,Mermer,blue
-3010,Siyah-şist,darkgrey
-3100,Kuvars-şist,purple
-3120,Mika-şist,grey
-3150,Mermer,blue