Search code examples
pythonplotlyplotly-python

How to adjust cell line width for hexbin mapbox?


Is it possible to adjust the cell linewidth using Plotly hexbin mapbox? I've had a look at the doco and can't find anything. If the linewidth can't be adjusted, can the color?

If I try to pass the linewidth parameter, it returns an error.

import pandas as pd
import plotly.figure_factory as ff

df = pd.DataFrame({
       'LAT': [-45,-44,-42,-41,-46,-44,-43,-45,-41,-45,-47],
       'LON': [-70,-71,-72,-72,-73,-74,-71,-70,-72,-70,-72],
       })

fig = ff.create_hexbin_mapbox(data_frame = df,
                                lat = 'LAT', 
                                lon = 'LON',
                                nx_hexagon = 5,
                                opacity = 0.5,
                                labels = {'color': 'Point Count'},
                                linewidth = 0.5,
                                mapbox_style = 'carto-positron',
                                zoom = 4
                                )
fig.show()

Output:

TypeError: create_hexbin_mapbox() got an unexpected keyword argument 'linewidth'

Solution

  • Just add the following to you code:

    fig.update_traces(marker_line_width = 0.5)
    

    That's a very small change compared to the default settings, though. I you use fig.update_traces(marker_line_width = 5) you'll get the following plot where the change is more visible:

    Plot

    enter image description here

    Comlplete code

    import pandas as pd
    import plotly.figure_factory as ff
    df = pd.DataFrame({
           'LAT': [-45,-44,-42,-41,-46,-44,-43,-45,-41,-45,-47],
           'LON': [-70,-71,-72,-72,-73,-74,-71,-70,-72,-70,-72],
           })
    
    fig = ff.create_hexbin_mapbox(data_frame = df,
                                    lat = 'LAT', 
                                    lon = 'LON',
                                    nx_hexagon = 5,
                                    opacity = 0.5,
                                    labels = {'color': 'Point Count'},
                                    # linewidth = 0.5,
                                    mapbox_style = 'carto-positron',
                                    zoom = 4
                                    )
    
    fig.update_traces(marker_line_width = 5)
    fig.show()