我正在尝试在情节上使用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):
欢呼