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