2020-11-30

Python Plotly - geocoding latitude and longitude - want different symbols depending on type of facility

I am geocoding a list of facilities and I want to the output to symbolize by whether they are a hospital or a clinic. Hospitals I want to appear as squares and clinics as circles. I can get my Plotly map working by mapping just one, but I'm unable to figure out how to have it plot different symbols by the facility type. I'm importing from a dataset that has the population (pop), location of the facility (location), latitude (lat), longitude (lon) and facility type (f_type). My dataset looks like this:

pop | location | lat | lon | f_type

20 | Cleveland, OH | 41.4993 | -81.6944 | hospital

Any help is appreciated.

import plotly.graph_objects as go
from plotly.offline import plot
from plotly.subplots import make_subplots
import plotly.graph_objects as go

import pandas as pd

df = pd.read_excel(r'D:\python code\data mgmt\listforgeorural.xlsx')
df.head()

fig = go.Figure(data=go.Scattergeo(
        locationmode = 'USA-states',
        lon = df['lon'],
        lat = df['lat'],
        f_type = df['f_type'],
      
        text = df['location']+'<br>Number of Projects:'+ df['f_type'].astype(str),
        mode = 'markers',
        marker = dict(
            size = 17,
            opacity = 0.9,
            reversescale = False,
            autocolorscale = False,
            symbol = {['square', 'circle']},
            line = dict(
                width=1,
                color='rgba(102, 102, 102)'
            ),
            colorscale = 'Blues',
            cmin = 0,
            color = df['pop'],
            cmax = df['pop'].max(),
            colorbar_title="Number of Rural Projects: 2015 - 2020"
        )))

fig.update_layout(
        title = 'List of Rural Projects by Location of Project Lead/PI',
        geo = dict(
            scope='usa',
            projection_type='albers usa',
            showland = True,
            landcolor = "rgb(222, 222, 222)",
            subunitcolor = "rgb(255, 255, 255)",
            countrycolor = "rgb(217, 217, 217)",
            countrywidth = 0.5,
            subunitwidth = 0.5
        ),
    )

fig.show()
plot(fig, filename='output.html')


from Recent Questions - Stack Overflow https://ift.tt/364gS1G
https://ift.tt/eA8V8J

No comments:

Post a Comment