Delete geospatial_visualization.py
Browse files- geospatial_visualization.py +0 -55
geospatial_visualization.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import geopandas as gpd
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
-
|
| 5 |
-
class GeospatialVisualizer:
|
| 6 |
-
def __init__(self):
|
| 7 |
-
# Replace the path below with the actual path where you've downloaded the shapefile
|
| 8 |
-
self.world = gpd.read_file("/path_to_your_downloaded_shapefile/naturalearth_lowres.shp")
|
| 9 |
-
|
| 10 |
-
def visualize(self, data, location_column, value_column):
|
| 11 |
-
# Merge data with world map
|
| 12 |
-
merged = self.world.merge(data, how='left', left_on=['name'], right_on=[location_column])
|
| 13 |
-
|
| 14 |
-
# Create the plot
|
| 15 |
-
fig, ax = plt.subplots(figsize=(15, 10))
|
| 16 |
-
merged.plot(column=value_column, ax=ax, legend=True,
|
| 17 |
-
legend_kwds={'label': value_column, 'orientation': 'horizontal'},
|
| 18 |
-
missing_kwds={'color': 'lightgrey'})
|
| 19 |
-
|
| 20 |
-
# Customize the plot
|
| 21 |
-
ax.set_title(f'{value_column} by Country')
|
| 22 |
-
ax.axis('off')
|
| 23 |
-
|
| 24 |
-
return fig
|
| 25 |
-
|
| 26 |
-
def create_choropleth(self, data, location_column, value_column):
|
| 27 |
-
# Merge data with world map
|
| 28 |
-
merged = self.world.merge(data, how='left', left_on=['name'], right_on=[location_column])
|
| 29 |
-
|
| 30 |
-
# Create the choropleth map
|
| 31 |
-
fig, ax = plt.subplots(figsize=(15, 10))
|
| 32 |
-
merged.plot(column=value_column, ax=ax, legend=True,
|
| 33 |
-
legend_kwds={'label': value_column, 'orientation': 'horizontal'},
|
| 34 |
-
cmap='YlOrRd', missing_kwds={'color': 'lightgrey'})
|
| 35 |
-
|
| 36 |
-
# Customize the plot
|
| 37 |
-
ax.set_title(f'Choropleth Map: {value_column} by Country')
|
| 38 |
-
ax.axis('off')
|
| 39 |
-
|
| 40 |
-
return fig
|
| 41 |
-
|
| 42 |
-
def create_bubble_map(self, data, lat_column, lon_column, size_column):
|
| 43 |
-
# Create a GeoDataFrame from the data
|
| 44 |
-
gdf = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(data[lon_column], data[lat_column]))
|
| 45 |
-
|
| 46 |
-
# Create the bubble map
|
| 47 |
-
fig, ax = plt.subplots(figsize=(15, 10))
|
| 48 |
-
self.world.plot(ax=ax, color='lightgrey')
|
| 49 |
-
gdf.plot(ax=ax, markersize=data[size_column]/data[size_column].max()*100, alpha=0.5)
|
| 50 |
-
|
| 51 |
-
# Customize the plot
|
| 52 |
-
ax.set_title(f'Bubble Map: {size_column} by Location')
|
| 53 |
-
ax.axis('off')
|
| 54 |
-
|
| 55 |
-
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|