gpt4 book ai didi

python - 密谋:如何添加自定义图例

转载 作者:行者123 更新时间:2023-12-04 15:55:41 33 4
gpt4 key购买 nike

我已经绘制了一个图,我想添加一个图例并在其中添加一些文本。

旧链接(现已断开)

https://plot.ly/~smirnod1/4/roc-curve/

编辑到相似剧情的链接:

https://plot.ly/~wonglynn2004/44/roc-plot-and-area-under-curve/#/code

这是一个示例-ROC曲线,我想将AUC放在图例中,但是我找不到有关微调图例内容的文档。

enter image description here

最佳答案

这将取决于您的图表类型以及图中数据的包含顺序。在与您在此处描述的情况类似的情况下,可以通过编辑跟踪的name属性来更改图例中显示的内容:

fig['data'][0]['name'] = 'ROC'
fig['data'][1]['name'] = 'AUC'

plotly :

enter image description here

代码:
import plotly.graph_objects as go
import numpy as np
#py.sign_in('username', 'api_key')

x1 = [0.0,
0.012533802635532472,
0.030175559084860713,
0.05447053268661201,
0.0876078465038417,
0.12868609692235053,
0.18101043052753574,
0.23509464737949093,
0.3178950079409366,
0.41812250504356785,
0.5606730480319354,
0.8282182255225995]

y1 = [0.0,
0.2159709618874773,
0.338777979431337,
0.4337568058076225,
0.5160314579552329,
0.5952813067150635,
0.6657592256503327,
0.7338173018753781,
0.7997580157289776,
0.8620689655172413,
0.925892316999395,
0.9824561403508771]

x2 = [0.0,
0.010301755590848607,
0.025368073142464694,
0.044640940893677296,
0.07138258144825514,
0.10636562647551187,
0.15169335107524573,
0.21243078507962398,
0.2978924325020389,
0.43808215650083704,
0.7974846546765678]

y2 = [0.00030248033877797946,
0.25650332728372655,
0.39231699939503933,
0.49122807017543857,
0.5795523290986085,
0.6636418632788869,
0.7380520266182699,
0.8061101028433152,
0.8702359346642469,
0.9319419237749547,
0.9879007864488808]

trace1 = {
"uid": "aa384d16-8ecd-11e8-8006-023b3ac8d721",
"line": {
"color": "darkorange",
"width": 2
},
"mode": "lines",
"name": "Baseline - 0.828",
"type": "scatter",
"x": x1,
"y": y1
}
trace2 = {
"uid": "aa385018-8ecd-11e8-8006-023b3ac8d721",
"line": {
"color": "darkorange",
"width": 2
},
"mode": "lines",
"name": "Refresh - 0.877",
"type": "scatter",
"x": x2,
"y": y2
}
data = [trace1, trace2]
layout = {
"title": "ROC Plot and Area Under Curve",
"width": 600,
"xaxis": {"title": "False Positive Rate"},
"yaxis": {"title": "True Positive Rate"},
"height": 500,
"legend": {
"x": 0.8,
"y": 0.1
},
"autosize": False
}
fig = go.Figure(data=data, layout=layout)

fig['data'][0]['name'] = 'ROC'
fig['data'][1]['name'] = 'AUC'

fig.show()

关于python - 密谋:如何添加自定义图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34727398/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com