creating a matplotlib scatter legend size related

前端 未结 6 2066
野性不改
野性不改 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:10

    I found this here, it is so easy and concise. Hope it helps

    import matplotlib.pyplot as plt
    import numpy as np
    
    import plotly.plotly as py
    import plotly.tools as tls
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    x = [0,2,4,6,8,10]
    y = [0]*len(x)
    s = [100,  400, 490, 600, 240, 160] # Specifies marker size
    
    ax.scatter(x,y,s=s)
    ax.set_title('Plot with Different Marker size, matplotlib and plotly')
    
    plotly_fig = tls.mpl_to_plotly( fig )
    plotly_fig['layout']['showlegend'] = True
    plotly_url = py.plot(plotly_fig, filename='mpl-marker-size')
    

提交回复
热议问题