gpt4 book ai didi

python - 带有多条轨迹的子图

转载 作者:太空狗 更新时间:2023-10-29 23:57:08 24 4
gpt4 key购买 nike

我正在尝试为以下 plotly 创建子 plotly :

enter image description here

enter image description here

我用于绘图的代码是:

radius_mean1 = df[df['diagnosis']==1]['radius_mean']
radius_mean0 = df[df['diagnosis']==0]['radius_mean']

trace_rm1 = go.Histogram(x = radius_mean1, opacity = 0.75, name = 'malignant')
trace_rm2 = go.Histogram(x = radius_mean0, opacity = 0.75, name = 'benign')

data2 = [trace_rm1,trace_rm2]
layout2 = go.Layout(barmode = 'overlay', title = 'radius mean')
fig2 = go.Figure(data=data2, layout=layout2)

py.iplot(fig2)

其他 plotly 类似

现在我使用我发现的以下代码来创建子图:

fig.append_trace(fig1['data'][1], 1, 1)
fig.append_trace(fig2['data'][0], 2, 1)
py.iplot(fig)

我明白了: enter image description here

我如何将良性和恶性结果添加到子图中?我似乎无法编辑 [0] 或 [1] 以同时显示两者,即将前 2 个图准确地放入我的子图中,同时显示恶性和良性,而不仅仅是一个或另一个。

最佳答案

这里的数据并不完整,所以我用一些demo数据来展示。

import numpy as np
import plotly.graph_objs as go
import plotly

a = np.random.normal(0,1,100)
b = np.random.normal(-2,5,100)

c = np.random.normal(0,1,100)
d = np.random.normal(-2,5,100)

fig = plotly.tools.make_subplots(rows=2,cols=1)

trace_rm1 = go.Histogram(x = a, opacity = 0.75, name = 'malignant')
trace_rm2 = go.Histogram(x = b, opacity = 0.75, name = 'benign')
fig.append_trace(go.Histogram(x = a, opacity = 0.75, name = 'benign'),1,1)
fig.append_trace(go.Histogram(x = b, opacity = 0.75, name = 'malignant'),1,1)
fig.append_trace(go.Histogram(x = c, opacity = 0.75, name = 'benign'),2,1)
fig.append_trace(go.Histogram(x = d, opacity = 0.75, name = 'malignant'),2,1)
fig.layout.update(go.Layout(barmode = 'overlay',))

plotly.offline.plot(fig)

result

关于python - 带有多条轨迹的子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46750462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com