Hey everyone,
Iâm trying to make subplots with these two plots and cannot make it work. I need the output to be a âdivâ with the two plots as subplots.
Like this:
plot 1
plot 2
Thank you for your help!
Eric
import plotly.graph_objs as go
import plotly.plotly as py
import plotly.figure_factory as ff
import plotly.offline as offline
from plotly import tools
import numpy as np
colorscales = [âBlackbodyâ,âBlueredâ,âBluesâ,âEarthâ,âElectricâ,âGreensâ,âGreysâ,âHotâ,âJetâ,âPicnicâ,âPortlandâ,
âRainbowâ,âRdBuâ,âRedsâ,âViridisâ,âYlGnBuâ,âYlOrRdâ]
data0 = list(np.random.normal(-5,.5,25))
data1 = list(np.random.normal(-3.5,1,25))
data2 = list(np.random.normal(0,2,25))
data3 = list(np.random.normal(1,1,25))
data4 = list(np.random.normal(5,3,25))
data5 = list(np.random.normal(7,5,25))
index = list(range(0,len(data0),1))
spectra = [
index,
data0,
data1,
data2,
data3,
data4,
data5
]
spectra = np.transpose(spectra)
traces1 = []
y_raw = spectra[:, 0] # wavelength
sample_size = spectra.shape[1]-1
for i in range(1, sample_size):
z_raw = spectra[:, i]
x = []
y = []
z = []
ci = int(255/sample_size*i) # ci = âcolor indexâ
for j in range(0, len(z_raw)):
z.append([z_raw[j], z_raw[j]])
y.append([y_raw[j], y_raw[j]])
x.append([i*2, i*2+1])
traces1.append(dict(
z=z,
x=x,
y=y,
colorscale=[ [i, ârgb(100,%d,255)â%ci] for i in np.arange(0, 1.1, 0.1)],
#colorscale=[[i, ârgb(%d,%d,255)â % (ci, ci)] for i in np.arange(0, 1.1, 0.1)],
#colorscale = colorscales[16],
showscale = False,
showlegend = True,
type=âsurfaceâ,
))
First subplot
fig = {âdataâ:traces1, âlayoutâ:{âtitleâ:âRibbon Plotâ}}
div1 = offline.plot(fig, filename=âDistplot with Multiple Datasetsâ,show_link=False, include_plotlyjs=False, output_type=âdivâ)
traces2 = [data0, data1, data2, data3, data4, data5]
group_labels = [âa0â, âa1â, âa2â, âa3â, âa4â, âa5â]
Second subplot
fig2 = ff.create_distplot(traces2, group_labels, bin_size=.2)
div2 = offline.plot(fig2, filename=âDistplot with Multiple Datasetsâ, show_link=False, include_plotlyjs=False, output_type=âdivâ)
print(div1)
print(div2)