我正在尝试在python中使用plotly绘制交互式小提琴图,但不适用于负值。
如果运行此代码,则输出(out.html)将不显示任何内容。如果删除所有“-”字符(或什至只是几个),小提琴图将出现在输出中,并显示正值。
import plotly
import numpy as np
outputFile = 'out.html'
data = [-2.728,-2.974,-1.824,-1.885,-2.646,-2.982,-2.538,-3.166,-2.585,-3.131,\
-2.949,-2.943,-2.485,-2.176,-2.240,-2.918,-2.342,-2.934,-1.506,-2.387,-2.899,\
-1.669,-2.840,-1.719,-2.388,-3.255,-2.785,-2.147,-1.800,-2.125,-3.082,-1.594,\
-2.368,-2.870,-4.473,-1.939,-2.819,-3.970,-2.635,-2.803,-2.362,-1.808,-1.562,\
-2.026,-2.682,-2.316,-3.689,-2.073,-2.534,-3.369,-2.398,-1.876,-2.264,-1.823,\
-2.905,-3.032,-2.139,-2.205,-2.468,-3.291,-2.259,-2.599,-1.368,-2.758,-1.734,\
-2.127,-3.392,-2.505,-2.828,-2.354,-3.611,-2.173,-1.964,-2.573,-2.872,-1.920,\
-1.587,-2.963,-3.073,-2.280,-3.292,-2.434,-1.905,-2.417,-3.977,-2.612,-2.770,\
-2.868,-2.318,-2.320,-2.327,-2.595,-1.942,-2.385,-2.203,-2.314,-2.403,-1.781,\
-2.570,-2.677,-2.692,-2.313,-2.859,-2.576,-2.827,-2.250,-1.668,-2.821,-2.291,\
-2.100,-3.346,-1.820,-1.533,-1.992,-1.835,-3.755,-2.940,-3.012,-2.608,-3.479,\
-2.557,-1.579,-1.587,-1.572,-1.844,-2.146,-3.172,-1.940,-1.633,-2.241,-2.029,\
-2.305,-2.689,-2.136,-2.181,-3.437,-2.520,-2.150,-1.709,-1.760,-2.447,-2.333,\
-2.496,-2.654,-3.280,-2.868,-1.831,-2.179,-1.931,-2.362,-2.306,-1.972,-2.471,\
-2.307,-2.362,-3.411,-2.375,-3.119,-1.818,-1.898,-2.099,-2.227,-1.969,-2.096]
dataD = np.array(data)
name = 'NAME'
colorbar_title = ''
final_data=[]
conf = {
"type": 'violin',
"x": name,
"y": dataD,
"legendgroup": name,
"scalegroup": name,
"name": name,
"side": 'negative',
"box": {
"visible" : True
},
"points": 'all',
"pointpos": 0,
"jitter": 0,
"scalemode": 'count',
"meanline": {
"visible": True
},
"line": {
"color": '#7cc2b6'
},
"marker": {
"size" : 1,
"line": {
"width": 0.5,
"color": '#7cc2b6'
}
},
"span": [
0
],
"showlegend": False
}
final_data.append(conf)
randomC = {
"type": 'violin',
"x": name,
"y": dataD,
"legendgroup": name,
"scalegroup": name,
"name": name,
"side": 'positive',
"box": {
"visible": True
},
"points": 'all',
"pointpos": 0,
"jitter": 0,
"scalemode": 'count',
"meanline": {
"visible": True
},
"line": {
"color": '#ada9c9'
},
"marker": {
"size" : 1,
"line": {
"width": 0.5,
"color": '#ada9c9'
}
},
"span": [
0
],
"showlegend": False
}
final_data.append(randomC)
fig = {
"data": final_data,
"layout" : {
"title": "Change title",
"yaxis": {
"rangemode": "normal",
"autorange": True
},
"violingap": 0,
"violingroupgap": 0,
"violinmode": "overlay"
}
}
plotly.offline.plot(fig, filename=outputFile, validate = False)
无错误消息。我期望有一个out.html显示带有负值的小提琴图。
答案 0 :(得分:0)
我不确定为什么选择禁用验证,但是如果启用验证,随后出现的错误将使您了解配置的问题。
特别是:
span
的配置不正确,因此请将其删除或修复x
应该改为x0