Hey @smail ,
I read @adamschroeder’s and @jlfsjunior’s answers and tried to create an example.
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
data = pd.read_csv("example.dat", sep = "\t")
# SUBPLOT CONFIG
fig = make_subplots(rows=1,
cols=3,
specs=[[{"type": "scatter"},
{"type": "scatter"},
{"type": "scatter"}
]
],
column_widths=[2.5, 2.5, 2.5],
shared_yaxes=True
)
# GHOST TRACES TRACE NAMES: ghost1 and ghost2
fig.add_trace(go.Scatter(x=None, y=None, name="ghost1", showlegend=False), row=1, col=1) #COLUMN 1
fig.add_trace(go.Scatter(x=None, y=None, name="ghost2", showlegend=False), row=1, col=2) #COLUMN 2
#Since we have 3 subplots
#x-axis -> xaxis, xaxis2, xaxis3
#When we add additional traces (2 ghost + 1 data)
#New x-axis -> xaxis4, xaxis5, xaxis6
fig.update_layout(xaxis4 = {'anchor': 'y', 'overlaying': 'x', 'side': 'top'}) #Ghost Axis Column1
fig.update_layout(xaxis5 = {'anchor': 'y2', 'overlaying': 'x2', 'side': 'top'}) #Ghost Axis Column2
fig.update_layout(xaxis6 = {'anchor': 'y3', 'overlaying': 'x3', 'side': 'top'}) #Data Axis Column3
# ADD TRACES
# ONLY TEMP (FIRST GRAPH)
fig.add_trace(go.Scatter(x=data["temperature"],
y=data["depth(m)"]*-1,
name="temperature",
mode='lines',
marker=dict(color="red"),
),
row=1, col=1
)
# ONLY PRESSURE-(PSIG) (SECOND GRAPH)
fig.add_trace(go.Scatter(x=data["pressure(psig)"],
y=data["depth(m)"]*-1,
name="pressure(psig)",
mode='lines',
marker=dict(color="blue"),
),
row=1, col=2
)
# TEMP + PRESSURE-(PSİG) (THIRD GRAPH)
fig.add_trace(go.Scatter(x=data["pressure(psig)"],
y=data["depth(m)"]*-1,
name="pressure_temp",
mode='lines',
marker=dict(color="green"),
),
row=1, col=3
)
fig.add_trace(go.Scatter(x=data["temperature"],
y=data["depth(m)"]*-1,
name="temp_pressure",
mode='lines',
marker=dict(color="purple"),
),
row=1, col=3
)
# UPDATE AXİS
#Ghost Traces (Column 1 and 2)
fig.update_traces(xaxis='x4',yaxis='y', selector = ({'name':'ghost1'}))
fig.update_traces(xaxis='x5',yaxis='y2', selector = ({'name':'ghost2'}))
#Set Range
fig.update_layout(xaxis4_range=[data["temperature"].min(),data["temperature"].max()])
fig.update_layout(xaxis5_range=[data["pressure(psig)"].min(),data["pressure(psig)"].max()])
#Real Data (Column 3)
fig.update_traces(xaxis='x3',yaxis='y3', selector = ({'name':'pressure_temp'}))
fig.update_traces(xaxis='x6',yaxis='y3', selector = ({'name':'temp_pressure'}))
print(fig.layout)
fig.show()
Feedbacks are welcome : )