Python 3.x 颜色条与Plotly中的等高线图重叠
我在轮廓的第一个子图(请看我在文章末尾包含的图像)的左侧和右侧获得我不理解的边距。此外,我无法在第二个绘图中正确定位颜色栏。如何修复代码Python 3.x 颜色条与Plotly中的等高线图重叠,python-3.x,plotly,contour,colorbar,Python 3.x,Plotly,Contour,Colorbar,我在轮廓的第一个子图(请看我在文章末尾包含的图像)的左侧和右侧获得我不理解的边距。此外,我无法在第二个绘图中正确定位颜色栏。如何修复代码 def bern(theta, z, N): """Bernoulli likelihood with N trials and z successes.""" return np.clip(theta**z * (1-theta)**(N-z), 0, 1) d
def bern(theta, z, N):
"""Bernoulli likelihood with N trials and z successes."""
return np.clip(theta**z * (1-theta)**(N-z), 0, 1)
def bern2(theta1, theta2, z1, z2, N1, N2):
"""Bernoulli likelihood with N trials and z successes."""
return bern(theta1, z1, N1) * bern(theta2, z2, N2)
def make_thetas(xmin, xmax, n):
xs = np.linspace(xmin, xmax, n)
widths =(xs[1:] - xs[:-1])/2.0
thetas = xs[:-1]+ widths
return thetas
thetas1 = make_thetas(0, 1, 101)
thetas2 = make_thetas(0, 1, 101)
X, Y = np.meshgrid(thetas1, thetas2)
a = 2
b = 3
z1 = 11
N1 = 14
z2 = 7
N2 = 14
prior = stats.beta(a, b).pdf(X) * stats.beta(a, b).pdf(Y)
likelihood = bern2(X, Y, z1, z2, N1, N2)
posterior = stats.beta(a + z1, b + N1 - z1).pdf(X) * stats.beta(a + z2, b + N2 - z2).pdf(Y)
layout = go.Layout(yaxis=dict(scaleanchor="x", scaleratio=1))
fig = make_subplots(rows=1, cols=3, subplot_titles=('Prior', 'Likelihood', 'Posterior'))
cbarlocs = [.28, .63, 1]
fig.add_trace(
go.Contour(
z= prior,
colorbar=dict(
#title='Color bar title', # title here
#titleside='right',
x = cbarlocs[0],
titlefont=dict(
size=14,
family='Arial, sans-serif') )
), 1, 1),
fig.update_layout( layout ) ,
fig.add_trace(
go.Contour(
z= likelihood,
colorbar=dict(
#title='Color bar title', # title here
#titleside='right',
x = cbarlocs[1],
titlefont=dict(
size=14,
family='Arial, sans-serif'))
), 1, 2),
fig.update_layout( layout ) ,
fig.add_trace(
go.Contour(
z= posterior,
colorbar=dict(
#title='Color bar title', # title here
#titleside='right',
x = cbarlocs[2],
titlefont=dict(
size=14,
family='Arial, sans-serif') )
), 1, 3),
fig.update_layout( layout )
fig.show()