小提琴图不适用于 python-plotly 中的负值
Violin plots do not work with negative values in python-plotly
我正在尝试使用 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 显示带有负值的小提琴图。
我不确定您为什么选择禁用验证,但如果您启用它,接下来的错误会让您了解您的配置有什么问题。
具体来说:
span
配置不正确,请删除或修复
x
应该是 x0
而不是
我正在尝试使用 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 显示带有负值的小提琴图。
我不确定您为什么选择禁用验证,但如果您启用它,接下来的错误会让您了解您的配置有什么问题。
具体来说:
span
配置不正确,请删除或修复x
应该是x0
而不是