I have some dataset in csv files(3 at total) and need to represent it in differents ways. They are necessarily line charts, box plots and histogram with kde(kernel density estimation).
I know how to plot them individually, but to make it more convenient I need to merge them into a single output. After consulting the reference I did write some code but it didnβt run.
Is there a way to combine make_subplots() with figure_factory.create_distplot()?
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.figure_factory as ff
import numpy as np
y1 = np.random.randn(200) - 1
y2 = np.random.randn(200)
y3 = np.random.randn(200) + 1
x = np.linspace(0, 1, 200)
fig = make_subplots(
rows=3, cols=2,
column_widths=[0.6, 0.4],
row_heights=[0.3, 0.6, 0.9],
specs=[[{"type": "scatter"}, {"type": ["box","box","box"]}],
[{"type": "scatter"}, {"type": ["histogram","histogram","histogram","scatter","scatter","scatter"], "rowspan": 2}],
[{"type": "scatter"}, None ]])
fig.add_trace(
go.Scatter(x = x,
y = y1,
hoverinfo = 'x+y',
mode='lines',
line=dict(color='rgb(0, 0, 0)',
width=1),
showlegend=False,
),
row=1, col=1
)
fig.add_trace(
go.Scatter(x = x,
y = y2,
hoverinfo = 'x+y',
mode='lines',
line=dict(color='rgb(246, 52, 16)',
width=1),
showlegend=False,
),
row=2, col=1
)
fig.add_trace(
go.Scatter(x = x,
y = y3,
hoverinfo = 'x+y',
mode='lines',
line=dict(color='rgb(16, 154, 246)',
width=1),
showlegend=False,
),
row=3, col=1
)
fig.add_trace(go.Figure(data=[go.Box(x=y1), go.Box(x=y2), go.Box(x=y3)]),
row=1, col=2
)
group_labels = ['Group 1', 'Group 2', 'Group 3']
hist_data = [y1, y2, y3]
fig.add_trace(
ff.create_distplot(hist_data, group_labels,
bin_size=.02, show_rug=False),
row=2, col=2
)
fig.show()
How can I plot these charts with an unique output.
P.S. the line charts need to be separated for better visualization.