<jupyter_start><jupyter_text>I'm going to update my values here. I won't persist these changes because a city's status may change multiple times and the size of the data set is very small, so this step takes very little time.<jupyter_code>update_date = '11_05_18'
updates_df = pd.read_csv('updates/updates_{}.csv'.format(update_date))
updates_df.head()
# updates_df.sort_values(by=['State', 'City'], ascending=[True, True], inplace=True)
df['status'] = updates_df['MAP_STATUS']

df.loc[df['status'] == 4]<jupyter_output><empty_output><jupyter_text>So far so good<jupyter_code># Updating Ordinance Status

d_text = {0: 'Ordinance Active - With No Response', 
          1: 'Ordinance Active - With Response Indicating No Immediate Repeal',
          2: 'Ordinance Active - With Committment To Review', 
          3: 'Ordinance Halted - With Committment to Review',
          4: 'Ordinance Repealed'}

df['statusText'] = df['status'].map(d_text)

# Updating Marker Color 

d_color = {0: 'rgba(255, 0, 0, 1.0)',
           1: 'rgba(255, 192, 203, 1.0)',
           2: 'rgba(255, 165, 0, 1.0)', 
           3: 'rgba(255, 255, 0, 1.0)', 
           4: 'rgba(127, 255, 0, 1.0)'}

df['color'] = df['status'].map(d_color)

# Creating Marker Line Color Primarily for Subplot Workaround 

d_line_color = {0: 'rgba(0, 0, 0, 1.0)', 1: 'rgba(0, 0, 0, 1.0)',
                2: 'rgba(0, 0, 0, 1.0)', 3: 'rgba(0, 0, 0, 1.0)',
                4: 'rgba(0, 0, 0, 1.0)'}

df['linecolor'] = df['status'].map(d_line_color)<jupyter_output><empty_output><jupyter_text>Let's check to see if that works<jupyter_code>df.loc[df['color'] == 'rgba(127, 255, 0, 1.0)']<jupyter_output><empty_output><jupyter_text>Looks good.<jupyter_code># This creates the text that appears at each point on the the scroll over
df['text'] = df['City'] + ', ' + df['State.1'] + '.' + ' ' + df['statusText']<jupyter_output><empty_output><jupyter_text>And now for the plotting!<jupyter_code># creating my trace dataframe
new_columns = ['lat', 'lon', 'text', 'status', 'statusText', 'color']

city_plots = pd.DataFrame(data = [df['Latitude'], df['Longitude'], df['text'], df['status'], df['statusText'], df['color']])
final_plots = city_plots.T
final_plots.columns = new_columns

# I created a 'subtitle' by plotting a sixth 'phantom' trace 
# However, it didn't look great, so I opted not to include it for now

subplot_text = ("<br> ^ Legend categories are toggle-able. Feel free to click them on and off. <br><br><b> Note:</b> This is not a complete map of communities with unconstitutional <br> anti-panhandling ordinances. Ordinances were targeted based <br> on local partnerships and resources. <br><br> More than <i>60%</i> of communities surveyed in a 2016 survey <br> had some form of panhandling ordinance. <br><br> Map by <NAME>: https://github.com/mattymecks.")

final_plots = final_plots.append({'lat': 44.49, 'lon': -66.57, 'text': 'subtitle', 'status': 5, 
                    'statusText': subplot_text, 'color':'rgba(255, 255, 255, 0.0)'}, ignore_index=True)
d_text[5] = subplot_text
d_color[5] = 'rgba(255, 255, 255, 0.0)'
d_line_color[5] = 'rgba(0, 0, 0, 0.0)'

# organizing the data by desired trace
traces_for_plot = []

for i in range(0,6): 
    trace_df = final_plots[final_plots['status'] == i]
    traces_for_plot.append(trace_df)

# building the traces
final_traces = []
i = 0

for trace in traces_for_plot:
    print(i)
    final_trace = go.Scattergeo(
           locationmode = 'USA-states',
            lon = trace['lon'],
            lat = trace['lat'],
            text = trace['text'],
            hoverinfo = 'text',
            mode = 'markers',
            name = d_text[i],
            marker = dict(
                size = 8,
                opacity = 0.85,
                symbol = 'circle',
                line = dict(
                    width=1,
                    color=d_line_color[i]), 
                color = d_color[i]
            ))
    final_traces.append(final_trace)
    i += 1
    
    
layout = go.Layout(showlegend=True, title = 'Targeted Cities with Active Anti-Panhandling Laws', 
                   legend = dict(
#                    orientation='h',
#                    yanchor='top',
#                     xanchor = 'center',
#                     x = 1.5,
                    y = .6,
                   tracegroupgap = 60
                   ),
                   geo = dict(scope = 'usa',
                            projection=dict(type='albers usa'),
                            showland = True,
                            landcolor = "rgb(180, 180, 180)",
                            subunitcolor = "rgb(217, 217, 217)",
                            countrycolor = "rgb(217, 217, 217)",
                            countrywidth = 0.5,
                            subunitwidth = 0.5))
                   
# # Make a figure object
fig = go.Figure(data=final_traces, layout=layout)

# Show in Browser and generate new html. CAUTION will overwrite old html
plotly.offline.plot(fig, validate=False, filename='city_locations_{}.html'.format(update_date))

# Send to Plotly and show in notebook
# plotly.offline.iplot(fig, validate=False, filename='test1.html')
print(len(final_traces))
final_traces[4]
# df.columns
# df.loc[df['State'] == 'Vermont']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14315431164901665, 'fraction_numerical': 0.03668683812405446, 'mean_word_length': 2.6275720164609053, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '166487', 'license': 'Apache-2.0', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1713, 'n_words': 468, 'path': 'Mapping.ipynb', 'repo_name': 'mattymecks/nlchp-mapping-project', 'size': '5293'}