简体   繁体   English

改变标记大小与 pandas 带标记的线图的列中的值成比例

[英]Vary marker sizes proportional to the values in a column for pandas line-plots with markers

I have a pandas dataframe from which I need to plot a line plot with markers.我有一个 pandas dataframe ,我需要从它 plot 一行 Z32FA6E1B78A9D40289553 标记。 For this purpose, I convert the dataframe into a pivot table where index= "Distance", columns= "system", values= "fscore" .为此,我将 dataframe 转换为 pivot 表,其中index= "Distance", columns= "system", values= "fscore" With the plot method as used in the code snippet below, I can get a line plot as shown below.使用下面代码片段中使用的plot方法,我可以得到如下所示的 plot 行。 However, how exactly can I vary the marker size based on the values in the lenth column (or a normalised score of the values in the lenth column)?但是,我怎样才能根据第lenth lenth中值的标准化分数)来改变标记大小?

在此处输入图像描述

Code snippet:代码片段:

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)

The original dataframe distPD原装 dataframe 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

You may consider plot without markers and add a scatter plot with size option:您可以考虑不带标记的plot并添加带有size选项的scatter点 plot:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM