creating a matplotlib scatter legend size related

前端 未结 6 2071
野性不改
野性不改 2020-12-04 20:46

I am looking for a way to include a (matplotlib) legend that describe the size of points in a scatter plot, as this could be related to another variable, like in this basic

6条回答
  •  感情败类
    2020-12-04 21:11

    I almost like mjp's answer, but it doesn't quite work because plt.plot's 'markersize' argument doesn't mean the same thing as plt.scatter's 's' argument. Your sizes will be wrong using plt.plot.

    Instead use:

        marker1 = plt.scatter([],[], s=a2.min())
        marker2 = plt.scatter([],[], s=a2.max())
        legend_markers = [marker1, marker2]
    
        labels = [
            str(round(a2.min(),2)),
            str(round(a2.max(),2))
            ]
    
        fig.legend(handles=legend_markers, labels=labels, loc='upper_right',
            scatterpoints=1)
    

提交回复
热议问题