add secondary description in axis values, plotly

前端 未结 1 1632
无人及你
无人及你 2020-12-22 06:01

I am using a dataframe which includes the following columns:

Country, GNI, CarSalesPerCap. I am using kmeans to create clusters. In the algorithm i pass

相关标签:
1条回答
  • 2020-12-22 06:38

    You can add a text element to your trace and it will allow you to overlay anything you want. If you add your country column then it will be displayed on hover. If you want a permanent label you can add annotations

    import plotly.graph_objs as go
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
    init_notebook_mode(connected=True)
    import pandas as pd
    df = pd.DataFrame({'country':["USA", "MEXICO", "CANADA"], 'x':[1, 2, 4], 'y':[5, 6, 7]})
    p0 = go.Scatter(
        x=df.x,
        y= df.y,
        mode='markers',
        marker=dict(
            color='#E90',
            size=15
        ),
        text = df.country,    
    )
    
    data = [p0]
    
    iplot(data)
    

    0 讨论(0)
提交回复
热议问题