This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import plotly.graph_objects as go | |
| # create race graph | |
| def create_race_graph(df_filtered): | |
| # Select columns for bar graph | |
| race_columns = ["WtNHP", "BlNHP", "AsnNHP", "Hsp1P", "OthNHP", "Rc2plNHP"] | |
| race_labels = [ | |
| "White", | |
| "Black or African American", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import plotly.graph_objects as go | |
| # filter data for BK01 | |
| df_bk01 = df_acs_cdta_2021[df_acs_cdta_2021['GeoID'].str.contains('BK01')] | |
| # select columns for bar graph | |
| race_columns = ['WtNHP', 'BlNHP', 'AsnNHP', 'Hsp1P', 'OthNHP', 'Rc2plNHP'] | |
| race_labels = ['White', 'Black or African American', 'Asian', 'Hispanic or Latino', | |
| 'Some Other Race', 'Two or More Races'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas as gpd | |
| import plotly.graph_objects as go | |
| from plotly.subplots import make_subplots | |
| import plotly.io as pio | |
| # convert to 4326 for plotly | |
| gdf_parks.to_crs(4326, inplace=True) | |
| gdf_cdta.to_crs(4326, inplace=True) | |
| # define trace for parks layer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas as gpd | |
| import contextily as ctx | |
| import matplotlib.pyplot as plt | |
| import matplotlib.patches as mpatches | |
| # convert to better crs for gpd | |
| gdf_parks.to_crs(2263, inplace=True) | |
| gdf_cdta.to_crs(2263, inplace=True) | |
| # new plot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas as gpd | |
| import plotly.graph_objects as go | |
| import plotly.io as pio | |
| import config | |
| # convert to 4326 to view in plotly | |
| gdf_cdta.to_crs(4326,inplace=True) | |
| # define a trace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas as gpd | |
| # import cdta | |
| cdta_url="https://data.cityofnewyork.us/api/geospatial/xn3r-zk6y?accessType=DOWNLOAD&method=export&format=Shapefile" | |
| gdf_cdta=gpd.read_file(cdta_url) | |
| # add acre column in gdf_cdta | |
| gdf_cdta['cdta_acres'] = round(gdf_cdta['shape_area'] / 43560) | |
| # get info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas as gpd | |
| import matplotlib.pyplot as plt | |
| import contextily as ctx | |
| # create a new plot using geopandas | |
| fig, ax = plt.subplots(figsize=(10,10)) | |
| gdf_parks.plot(ax=ax,edgecolor='black', alpha=0.5) | |
| # add any additional features to the plot | |
| ax.set_title('NYC Park Properties', fontdict={"size":20}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas as gpd | |
| # define url | |
| parks_url = 'https://data.cityofnewyork.us/api/geospatial/enfh-gkve?method=export&format=Shapefile' | |
| gdf_parks = gpd.read_file(parks_url) # import shapefile as gdf | |
| # change crs | |
| gdf_parks.to_crs(2263, inplace=True) | |
| # preview gdf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import packages | |
| import matplotlib.pyplot as plt | |
| import contextily as ctx | |
| # plot map use helper function | |
| def plot_column_from_dict_facecolor(gdf, col_label_cmap_dict, jstevens_col_mats, | |
| alpha=0.85, font_size=14, save=False): | |
| """ | |
| Takes in gdf, column label cmap dictionary, and color matrix | |
| Also uses plot_inset_legend helper function to create plots |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import necessary packages | |
| import matplotlib.pyplot as plt | |
| import matplotlib.patches as mpatches | |
| import matplotlib.colors as mcolors | |
| import matplotlib.collections as mcollect | |
| # helper function to plot inset legend | |
| def plot_inset_legend(ax, color_matrix, x_label='X Label'): | |
| """ | |
| Takes in axes from plot, color_matrix and optional x label arg |
NewerOlder