1

我正在尝试在绘图上使用 2 xaxis(相同的 yaxis)。基本上,我想在顶部 X 轴和底部 X 轴上有不同的标签,我认为可以通过创建 2 条轨迹来实现,其中一条是空的,但使用它的 x 轴。我已经检查了 2 yaxis 的类似示例,但使用 2 xaxis 似乎不起作用。

基本上,我想要下面的图,但在顶部 x 轴上有不同的标签:

图片

import plotly
import numpy as np

outputFile = "out.html"
cols=10
rows=100

dataD = np.random.rand(10,100)

names = ["name1", "name2","name3","name4","name5",\
             "name6", "name7","name8","name9","name10"]
nums = ["2", "3","1","2","12","3", "2","28","1","40"]

final_data1=[]
final_data2=[]

for i in range(dataD.shape[0]):

    conf = {
        "type": "violin",
        "x0": names[i],
        "y": dataD[i,:],
        "name": names[i],
        "xaxis": "x1",
        "yaxis": "y"
    }
    final_data1.append(conf)
    topNum= {
        "type": "violin",
        "x0": nums[i],
        "y": [],
        "showlegend": False,
        "xaxis": "x2",
        "yaxis": "y"
    }
    final_data2.append(topNum)

fig = {
    "data": [final_data1,final_data2],
    "layout" : {
        "title": "Random title",
        "xaxis": {
            "showgrid":True,
            "showline":True,
            "tickangle": 270,
            "side":"bottom",
            "anchor": "y"
        },
        "xaxis2":{
            "overlaying":"x1",
            "side":"top",
            "anchor": "y"
        },
        "yaxis": {
            "zeroline": False,
        },
        "hovermode": "closest"
    }
}
plotly.offline.plot(fig, filename=outputFile, validate = False)

这是输出,显然是错误的(我什至不明白为什么标签从 -1 变为 6):

图片

干杯

4

0 回答 0