改变标记大小,使其与带有标记的线图的列中的值成比例

2024-10-03 09:09:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个熊猫数据框,我需要从中绘制一个带有标记的线图。为此,我将数据帧转换为一个透视表,其中index= "Distance", columns= "system", values= "fscore"。使用下面代码段中使用的plot方法,我可以得到如下所示的线图。但是,如何根据lenth列中的值(或lenth列中的值的标准化分数)改变标记大小

enter image description here

代码段:

plotPD = df.pivot(index="Distance", columns="system", values="fscore").fillna(0)
ax = plotPD.plot(
    marker="H",
    title="plotTitle",
    xticks=(range(0, len(plotPD.index) + 2, 2)),
    yticks=np.arange(0, 1.1, 0.1),
)
ax.set_xlabel(plotPD.index.name, fontsize=14)

原始数据帧distPD

    system  Distance  lenth  summ    fscore
0      L2S        12     45    31  0.688889
1      L2S         9     84    52  0.619048
2      L2S         1   1685  1471  0.872997
3      L2S         2    578   403  0.697232
4      L2S        13     47    30  0.638298
279  BiAFF        17      9     8  0.888889
280  BiAFF        19      7     5  0.714286
281  BiAFF        21      5     5  1.000000
282  BiAFF        20      4     4  1.000000
283  BiAFF        26      2     2  1.000000

Tags: columns数据标记indexplot代码段systemdistance
1条回答
网友
1楼 · 发布于 2024-10-03 09:09:56

您可以考虑没有标记的^ {CD1>},并用^ {< CD3>}选项添加^ {< CD2>}图:

plotPD.plot(marker="",..., zorder=1) # or simply remove marker option
plt.scatter(df.Distance, df.fscore, s=df.lenth, zorder=2) # not sure of your x, y

相关问题 更多 >