首页 > 解决方案 > 绘制子图分组 x 轴

问题描述

我在 x 轴上有一个带有不同组的箱线图的子图。我想为 x 轴上的不同组而不是不同的子图使用相同的颜色。怎么做?

x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
     'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2',
     'day 3', 'day 3', 'day 3', 'day 3', 'day 3', 'day 3']
cat = go.Box(
    x=x,
    y=np.random.randn(18)-1,
    name='cat',
    marker=dict(
        outliercolor='rgba(255,0,0,0)'
    )

)
dog = go.Box(
    x=x,
    y=np.random.randn(18)*1000,
    name='dog',
    marker=dict(
        outliercolor='rgba(255,0,0,250)'
    )
)

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

fig.append_trace(cat, 1, 1)
fig.append_trace(dog, 1, 2)

fig['layout'].update(height=600, width=1000, title='cats and dogs day1-3')
py.iplot(fig, filename='simple-subplot-with-annotations')

或者,我可以将所有轨迹添加到一个list-type 变量中,为每个组(即第 1 天、第 2 天、第 3 天)创建不同的颜色,但是每个组的 y 轴刻度是如此不同,这会使我的情节不清楚1 种类型的迹线(即,cat与 相比,值范围要低得多dog)。

标签: pythonplotlyjupyter

解决方案


推荐阅读