我在 Plotly 社区发布了这个问题:https://community.plotly.com/t/why-does-the-tooltip-show-on-the-wrong-point-in-scatter-plot/78835 。我在这里再次发布以获得更多回复。
我有一个散点图。当我将鼠标悬停在这些点上时,显示值的工具提示会显示在错误的点上:
这是 Plotly 中的错误吗?有什么办法可以解决吗
谢谢你。
编辑:
GetSet 要求我发布数据和布局:
数据:
[
{
"type":"scatter",
"mode":"markers",
"x":[
11.296296296296296,
9.444444444444445,
9.814814814814815,
9.351851851851851,
10.87962962962963,
14.23611111111111,
13.935185185185185,
11.73611111111111,
12.731481481481481,
16.13425925925926,
13.518518518518519,
12.222222222222221,
12.430555555555555,
10.532407407407407,
11.50462962962963,
8.88888888888889,
9.328703703703704,
12.939814814814815,
14.027777777777779,
14.699074074074074,
15.023148148148149,
16.38888888888889,
14.976851851851851,
11.875,
14.560185185185185,
16.15740740740741,
14.837962962962964,
15.833333333333334,
15.856481481481481,
13.981481481481481,
15.694444444444445,
16.89814814814815,
18.14814814814815,
17.314814814814813,
15.4,
14.305555555555555,
14.907407407407407,
12.61574074074074,
12.268518518518519,
9.027777777777779,
8.356481481481481,
9.907407407407407,
13.00925925925926,
13.449074074074074,
12.222222222222221,
10.50925925925926,
8.796296296296296,
8.541666666666666,
8.287037037037036,
5.185185185185185,
11.13425925925926,
10.833333333333334,
10.833333333333334,
8.703703703703704,
3.7731481481481484,
5.092592592592593,
6.736111111111111,
6.944444444444445,
8.26388888888889,
8.86574074074074,
9.027777777777779,
6.296296296296297,
7.060185185185185,
8.425925925925926,
6.736111111111111,
6.018518518518518,
5.601851851851852,
3.125,
1.875,
1.2037037037037037,
2.5231481481481484,
5.138888888888889,
4.305555555555555,
2.638888888888889,
-0.23148148148148148,
-1.3425925925925926,
0.20833333333333334,
-2.5462962962962963,
-3.5416666666666665,
-2.986111111111111,
-4.375,
-1.5046296296296295,
-4.537037037037037,
-3.7962962962962963,
8.564814814814815,
10.694444444444445,
8.587962962962964,
9.398148148148149,
10.856481481481481,
10,
9.25925925925926,
7.662037037037037,
5.486111111111111,
9.027777777777779,
9.62962962962963,
8.75,
15.917874396135266,
13.00925925925926,
9.88425925925926,
6.712962962962963,
11.319444444444445,
11.064814814814815,
10.972222222222221,
10.416666666666666,
8.333333333333334,
6.782407407407407,
6.273148148148148,
10.416666666666666,
9.907407407407407,
8.703703703703704,
8.935185185185185,
6.50462962962963,
4.606481481481482,
0.7870370370370371,
0.39351851851851855,
1.3657407407407407,
0.5092592592592593,
-1.7824074074074074,
-0.7870370370370371,
1.5509259259259258,
1.9675925925925926,
-1.3425925925925926,
2.060185185185185,
3.8425925925925926,
1.4351851851851851,
0.16203703703703703,
6.25,
5.324074074074074,
7.037037037037037,
8.518518518518519,
9.398148148148149,
7.569444444444445,
6.273148148148148,
3.1712962962962963,
1.2731481481481481,
0.9027777777777778,
1.5942028985507246,
4.62962962962963,
6.898148148148148,
6.833333333333333,
5.579710144927536,
6.416666666666667,
5.99537037037037,
7.939814814814815,
11.712962962962964,
10.277777777777779,
8.726851851851851,
7.106481481481482,
6.157407407407407,
6.736111111111111,
7.75462962962963,
4.513888888888889,
3.564814814814815,
0.9953703703703703,
1.0185185185185186,
0.9490740740740741,
1.5509259259259258,
2.9166666666666665,
2.013888888888889,
5.5092592592592595,
3.888888888888889,
3.888888888888889,
3.1481481481481484,
1.25,
6.1342592592592595,
6.481481481481482,
2.8472222222222223,
8.171296296296296,
13.703703703703704,
6.62037037037037,
4.74537037037037,
8.981481481481481,
12.476851851851851,
12.152777777777779,
10.462962962962964,
8.356481481481481,
11.435185185185185,
11.435185185185185,
12.662037037037036,
11.273148148148149,
9.953703703703704,
7.318840579710145,
4.675925925925926,
4.282407407407407,
11.435185185185185,
13.61111111111111,
11.157407407407407,
9.027777777777779,
5.833333333333333,
4.8842592592592595,
4.861111111111111,
6.342592592592593,
6.111111111111111,
8.449074074074074,
9.88425925925926,
10.578703703703704,
11.11111111111111,
10.231481481481481,
8.564814814814815,
9.00462962962963,
8.796296296296296,
10.162037037037036,
8.26388888888889,
10.300925925925926,
9.814814814814815,
11.875,
7.569444444444445,
10.532407407407407,
10.393518518518519,
11.087962962962964,
9.050925925925926,
7.152777777777778,
6.296296296296297,
9.12037037037037,
12.685185185185185,
10.949074074074074,
12.87037037037037,
13.726851851851851,
11.018518518518519,
10.48611111111111,
16.666666666666668,
14.976851851851851,
14.930555555555555,
15.671296296296296,
16.22685185185185,
13.333333333333334,
12.893518518518519,
13.333333333333334,
14.23611111111111,
16.412037037037038,
14.953703703703704,
11.064814814814815,
10.462962962962964,
10.856481481481481,
10.76388888888889,
13.449074074074074,
15.625,
17.037037037037038,
15.37037037037037,
13.541666666666666,
11.481481481481481,
13.333333333333334,
13.472222222222221,
15.578703703703704,
17.569444444444443,
14.74537037037037,
14.351851851851851,
18.078703703703702,
15.37037037037037,
13.796296296296296,
17.15277777777778,
17.824074074074073,
17.77777777777778,
18.40277777777778,
17.77777777777778,
20.74074074074074,
23.24074074074074,
25.53240740740741,
25.76388888888889,
24.537037037037038,
23.10185185185185,
21.50462962962963,
21.52777777777778,
21.550925925925927,
22.24537037037037,
21.319444444444443,
21.89814814814815,
22.26851851851852,
21.78240740740741,
18.21759259259259,
21.01851851851852,
22.26851851851852,
24.814814814814813,
20.416666666666668,
18.72685185185185,
19.189814814814813,
19.60648148148148,
18.171296296296298,
17.685185185185187,
18.194444444444443,
17.5,
17.98611111111111,
16.064814814814813,
17.40740740740741,
21.62037037037037,
25.439814814814813,
23.49537037037037,
21.75925925925926,
23.24074074074074,
19.12037037037037,
18.078703703703702,
20.949074074074073,
21.921296296296298,
18.333333333333332,
17.962962962962962,
18.51851851851852,
18.287037037037038,
17.662037037037038,
15.76388888888889,
17.24537037037037,
18.26388888888889,
17.199074074074073,
15.532407407407407,
17.662037037037038,
16.875,
20.09259259259259,
19.76851851851852,
17.36111111111111,
17.40740740740741,
17.12962962962963,
17.89351851851852,
16.38888888888889,
16.319444444444443,
14.86111111111111,
13.518518518518519,
15.439814814814815,
15.277777777777779,
16.96759259259259,
17.77777777777778,
21.550925925925927,
20.23148148148148,
19.328703703703702,
20.833333333333332,
21.34259259259259,
20.208333333333332,
18.75,
21.34259259259259,
23.125,
22.01388888888889,
21.25,
20,
20.925925925925927,
20.162037037037038,
18.77314814814815,
16.50462962962963,
15.439814814814815,
15.25462962962963,
15.11574074074074,
14.23611111111111,
14.930555555555555,
17.430555555555557,
18.935185185185187,
18.796296296296298,
19.23611111111111,
22.40740740740741,
22.800925925925927,
22.916666666666668,
23.21759259259259,
23.49537037037037,
24.88425925925926,
22.38425925925926,
20.37037037037037,
17.685185185185187,
16.15740740740741,
16.99074074074074,
18.958333333333332,
20.27777777777778,
19.583333333333332,
16.89814814814815,
18.75,
16.85185185185185,
13.402777777777779,
13.171296296296296,
13.425925925925926,
15.347222222222221
],
"y":[
92,
267,
277,
300,
291,
139,
104,
266,
275,
287,
278,
316,
173,
133,
238,
275,
277,
277,
183,
139,
143,
274,
278,
277,
268,
279,
204,
174,
287,
281,
281,
289,
293,
198,
146,
138,
139,
300,
279,
288,
220,
205,
175,
285,
210,
178,
165,
167,
173,
262,
175,
164,
266,
310,
229,
208,
300,
288,
290,
300,
296,
228,
224,
302,
305,
282,
286,
293,
230,
217,
305,
283,
285,
275,
250,
185,
191,
296,
283,
274,
261,
209,
222,
225,
257,
235,
304,
278,
257,
200,
201,
199,
213,
220,
219,
219,
213,
198,
192,
328,
315,
279,
250,
210,
218,
285,
274,
272,
283,
294,
219,
214,
235,
258,
287,
252,
263,
141,
102,
264,
265,
273,
271,
273,
143,
113,
286,
296,
275,
254,
260,
142,
108,
265,
268,
271,
280,
193,
95,
94,
248,
258,
270,
273,
267,
122,
90,
266,
270,
264,
263,
270,
125,
104,
282,
297,
290,
291,
285,
142,
106,
95,
81,
83,
75,
216,
132,
98,
273,
293,
276,
303,
271,
122,
89,
268,
259,
266,
274,
273,
127,
92,
257,
263,
246,
263,
273,
131,
110,
301,
265,
264,
256,
126,
92,
89,
90,
267,
256,
274,
260,
127,
95,
268,
255,
284,
274,
187,
102,
96,
239,
235,
242,
245,
256,
144,
106,
102,
257,
253,
255,
253,
127,
92,
245,
241,
258,
262,
259,
124,
93,
238,
264,
261,
128,
97,
89,
86,
227,
266,
293,
248,
122,
88,
93,
96,
244,
232,
248,
93,
92,
93,
252,
263,
275,
261,
137,
85,
88,
275,
255,
248,
255,
222,
83,
85,
227,
248,
246,
254,
211,
85,
87,
247,
281,
275,
246,
120,
92,
96,
272,
238,
234,
263,
256,
120,
81,
90,
255,
250,
263,
273,
119,
96,
253,
237,
257,
216,
147,
91,
92,
254,
252,
257,
126,
90,
95,
97,
267,
260,
238,
244,
279,
125,
87,
102,
89,
90,
84,
80,
77,
77,
77,
81,
234,
263,
259,
86,
82,
274,
265,
254,
231,
259,
116,
92,
89,
248,
262,
246,
269,
139,
119,
260,
270,
268,
242,
111,
113,
111,
261,
244,
232,
214,
275,
144,
120,
245,
253,
246,
238,
256,
181,
180,
293
],
"name":"°C",
"marker":{
"color":[
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#89d300",
"#4d9700",
"#4d9700",
"#89d300"
],
"size":3,
"opacity":1
}
}
]
布局:
{
"title":{
"text":"Scatter Plot",
"font":{
"color":"#3dcd58",
"family":"Nunito-Regular",
"size":18
},
"xanchor":"left",
"x":0
},
"font":{
"color":"#333",
"family":"Nunito-Regular"
},
"dragmode":"lasso",
"autosize":false,
"width":425,
"height":400,
"margin":{
"l":20,
"r":15,
"b":30,
"t":30
},
"plot_bgcolor":"#ffffff",
"showlegend":false,
"yaxis":{
"title":"kWh",
"showticklabels":false,
"range":[
62.35,
340.65
]
},
"xaxis":{
"title":"°C",
"titlefont":{
"color":"#89d300"
},
"showticklabels":false,
"side":"bottom",
"range":[
-6.052083333333334,
27.278935185185187
]
}
}
这不是一个错误,这是布局配置中具有
"hovermode": "x"
时的预期行为,您需要使用 "hovermode": "closest"
来代替。
请注意,默认使用
"hovermode": "x"
表示您使用的是过时版本的 Plotly.js,自 Plotly.js-2.0.0 (changelog) 以来,默认悬停模式设置为“最接近”。
人们使用过时的(< 2.0.0) version is because they refer to "plotly-latest" as source file, thinking it's the latest obviously while it's not :
从 v2 开始,“plotly-latest”输出(例如
)将不再更新 CDN,并将保留在最后一个 v1 补丁 v1.58.5。因此,要使用 使用plotly.js v2及更高版本的CDN,您必须指定一个准确的 plotly.js 版本。https://cdn.plot.ly/plotly-latest.min.js