首页 > 解决方案 > 标记根据表示点的数量改变大小的散点图

问题描述

我正在绘制一个简单的散点图: 当前地块

它正确地表示了我的数据,但是有许多坐标为 (1.00,1.00) 的数据点,并且在图中,它们出现在一个标记下(右上角)。我想要一个功能,根据它所代表的点数来改变每个标记的大小。将不胜感激任何帮助。这是我的代码:

def saveScatter(figureTitle, xFeature, yFeature, xTitle, yTitle):
''' save a scatter plot of xFeatures vs yFeatures '''

    fig = plt.figure(figsize=(8, 6), dpi=300)
    ax = fig.add_subplot(111)    
    ax.scatter(dfModuleCPositives[names[xFeature]][:], dfModuleCPositives[names[yFeature]][:], c='r', marker='x', alpha=1, label='Module C Positives')
    ax.scatter(dfModuleCNegatives[names[xFeature]][:], dfModuleCNegatives[names[yFeature]][:], c='g', alpha=0.5, label='Module C Negatives')
    ax.scatter(dfModuleDPositives[names[xFeature]][:], dfModuleDPositives[names[yFeature]][:], c='k', marker='x', alpha=1, label='Module D Positives')
    ax.scatter(dfModuleDNegatives[names[xFeature]][:], dfModuleDNegatives[names[yFeature]][:], c='b', alpha=0.5, label='Module D Negatives')    
    ax.set_xlabel(xTitle, fontsize=10)
    ax.set_ylabel(yTitle, fontsize=10)
    ax.set_title(figureTitle)
    ax.grid(True)
    ax.legend(loc="lower right")
    fig.tight_layout()
    plt.show()
    return ax

标签: pythonscatter-plot

解决方案


推荐阅读