Reputation: 179
So I'm trying to plot the well log using plotly, but I just found out that plotly doesn't have a feature like fill-in-between matplotlib, anyone here knows how to make it in my case? This is the plot I want to be plotted in plotly
the color only shows in certain depth, based on Litho Code columns of my dataframe
here's sample of my data
Well | Depth | GR | Litho Code |
---|---|---|---|
A | 146.6088 | 63.1578 | |
A | 146.7612 | 59.0457 | 8 |
A | 146.9136 | 57.9425 | 8 |
A | 147.2184 | 60.1089 | |
A | 147.3708 | 59.1862 | 8 |
A | 147.5232 | 57.9626 | 8 |
for the color, it depends on the value in litho code column, which 8 indicates yellow. so far, this is what I got in plotly
logplot = make_subplots(rows=1, cols=8, shared_yaxes = True)
logplot.add_trace(go.Scatter(x=df['GR'], y=df['DEPTH'], name='GR', line_color='green'), row=1, col=1)
logplot.update_xaxes(col=1, title_text='GR', linecolor='#585858')
logplot.update_xaxes(showline=True, linewidth=2, linecolor='black', mirror=True, ticks='inside', tickangle=0)
logplot.update_yaxes(tickmode='linear', tick0=0, dtick=250, showline=True, linewidth=2, ticks='outside', mirror=True, linecolor='black')
logplot.update_yaxes(row=1, col=1, autorange='reversed')
logplot.update_layout(height=750, width=650, showlegend=False, template = 'plotly', margin={'r':0,'t':50,'l':0,'b':0})
anyone here know how to code them like matplotlib but in plolty? maybe someone knows the trick, any help would appreciate, thanks!
Upvotes: 0
Views: 320
Reputation: 35145
To display the same effect as fill_between, you can use the line mode of plotly scatter plot to fill. The fill you need can be drawn using a combination of a line chart that draws a threshold and a line chart that draws a lower limit. As a sample, we set the data manually. For more information on line mode fills for scatter plots, see this.
from plotly.subplots import make_subplots
import plotly.graph_objects as go
#logplot = make_subplots(rows=1, cols=8, shared_yaxes = True)
logplot = go.Figure()
logplot.add_trace(go.Scatter(x=df['GR'], y=df['Depth'], name='GR', line_color='green'))
# logplot.update_xaxes(title_text='GR', linecolor='#585858')
# logplot.update_xaxes(showline=True, linewidth=2, linecolor='black', mirror=True, ticks='inside', tickangle=0)
# logplot.update_yaxes(tickmode='linear', tick0=0, dtick=250, showline=True, linewidth=2, ticks='outside', mirror=True, linecolor='black')
# logplot.update_yaxes(autorange='reversed')
logplot.update_layout(height=500, width=450, showlegend=False, template='plotly', margin={'r':0,'t':50,'l':0,'b':0})
logplot.add_trace(go.Scatter(x=[59.0457, 57.9425], y=[146.7612, 146.9136], mode='lines', line_color='green', fill='none'))
logplot.add_trace(go.Scatter(x=[59.0457, 57.9425], y=[146.9136, 146.9136], mode='lines', line_color='yellow', fill='tonexty'))
logplot.show()
Upvotes: 1