Documentation of plotly说,使用参数 range 我们可以设置轴的限制,例如 range = [0, 10] 将轴最小值设置为0,最大值设置为10.根据文档,它可以在图形,布局,场景或x轴下使用 . 实际上 ScatterLayout 接受 xaxisyaxis 参数,它们是dicts或 plotly.graph_objs.XAxis 对象,并且可以提供 range 值 . 但是,通过尝试我能想象到的所有变化,它显然无法设置限制 . 此外,第一个子图似乎低于其他子图 . 请参阅下面的最低工作示例,该示例可以在任何Jupyter笔记本中运行 .

奖金问题:为什么 fillfill 参数无法设置点的填充颜色?

import plotly
import plotly.tools
import plotly.graph_objs
plotly.offline.init_notebook_mode()

data = {
    'A': {
        'x': [1.0, 2.0, 6.0, 8.0],
        'y': [34.0, 36.0, 38.0, 40.0],
        's': [0.00416, 0.01125, 0.0038, 0.002]
    },
    'B': {
        'x': [1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 3.0, 2.0, 2.0, 3.0,
            4.0, 2.0, 4.0, 5.0, 6.0, 7.0, 7.0],
        'y': [30.0, 32.0, 32.0, 33.0, 34.0, 34.0, 34.0, 35.0,
            36.0, 36.0, 36.0, 38.0, 38.0, 38.0, 38.0, 38.0, 40.0],
        's': [0.029999999999999999, 0.19625000000000001, 0.070833333333333331,
            0.0079166666666666673, 0.23749999999999999, 0.37708333333333333,
            0.028333333333333332, 0.018749999999999999, 0.51875000000000004,
            0.066666666666666666, 0.02375, 0.0066666666666666671,
            0.012083333333333333, 0.01125, 0.016666666666666666,
            0.0058333333333333336, 0.0275]
    },
    'C': {
        'x': [1.0, 2.0, 1.0, 2.0, 2.0],
        'y': [32.0, 32.0, 34.0, 34.0, 36.0],
        's': [0.029208333333333333, 0.0050000000000000001, 0.03820833333333333,
            0.022833333333333334, 0.029083333333333333],
    },
    'D': {
        'x': [0.0, 1.0, 0.0, 1.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 1.0, 1.0,
            2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 7.0],
        'y': [30.0, 30.0, 31.0, 31.0, 32.0, 32.0, 33.0, 33.0, 34.0, 34.0, 34.0,
            35.0, 36.0, 36.0, 36.0, 36.0, 36.0, 36.0, 38.0, 38.0, 38.0, 38.0,
            38.0, 40.0, 40.0],
        's': [0.0087500000000000008, 0.050000000000000003, 0.008750000000000000,
            0.013333333333333334, 0.60875000000000001, 0.16666666666666666,
            0.04583333333333333, 0.00070833333333333338, 0.73320833333333335,
            0.54541666666666666, 0.040833333333333333, 0.02, 0.0700000000000,
            0.73124999999999996, 0.1125, 0.066666666666666666, 0.02083333332,
            0.0083333333333333332, 0.027916666666666666, 0.0212500000000000,
            0.070833333333333331, 0.11666666666666667, 0.040833333333333333,
            0.059999999999999998, 0.1125]
    }
}

xlim = [0, 9]
ylim = [13, 60]

traces = []

for name in sorted(data.keys()):
    sub = data[name]

    traces.append(plotly.graph_objs.Scatter(x = sub['x'], y = sub['y'],
                                        mode = 'markers',
                                        marker = dict(
                                            size = sub['s'],
                                            sizemode = 'area',
                                            sizeref = 0.0001),
                                        name = name,
                                        fill = '#333333',
                                        showlegend = False,
                                        xaxis = dict(range = xlim),
                                        yaxis = dict(range = ylim))
                                    )

fig = plotly.tools.make_subplots(rows=2,
                                cols=2,
                                subplot_titles=sorted(data.keys())
                            )

for i, trace in enumerate(traces):
    fig.append_trace(trace, row = i // 2 + 1, col = (i % 2) + 1)

fig['layout'].update(height = 1000, width = 600, title = main_title,
                    xaxis = dict(range = xlim), yaxis = dict(range = ylim))

plotly.offline.iplot(fig, show_link = False)

结果如下所示:

failed to set axes limits