Global Disease Outbreak (June 2024) #850
nimisha-18
announced in
2024 Plotnine Contest
Replies: 3 comments 6 replies
|
NOTE: The final figure in the submission uses matplotlib plus basemap. The first try with plotnine did not go all the way. This is the plotnine part with the resulting figure. import pandas as pd
import geopandas as gpd
import contextily as ctx
import matplotlib.pyplot as plt
from plotnine import ggplot, aes, geom_point, theme_minimal, labs, scale_color_brewer, scale_size
# Load the data
data = pd.read_csv('world_disease_data.csv')
df = pd.DataFrame(data)
# Convert to GeoDataFrame
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df['Lng'], df['Lat']))
# Set the coordinate reference system (CRS) to EPSG:4326 (WGS 84)
gdf.set_crs(epsg=4326, inplace=True)
# Reproject to EPSG:3857
gdf = gdf.to_crs(epsg=3857)
# Convert GeoDataFrame to Pandas DataFrame for Plotnine
gdf['x'] = gdf.geometry.x
gdf['y'] = gdf.geometry.y
# Create a 'Plotnine' plot for visualization
plot = (
ggplot(gdf) +
aes(x='x', y='y', color='Disease', size='Rating') +
geom_point(alpha=0.6) +
theme_minimal() +
labs(title='Disease Outbreaks', x='Longitude', y='Latitude', color='Disease', size='Rating') +
scale_color_brewer(type='qual', palette='Dark2') +
scale_size(range=(2, 10))
)
plotIt was possible to continue using plotnine plus basemap. from plotnine import *
plot2 = (
plot # from above
+ guides(
color=guide_legend(
theme=theme(
legend_position=(0.965, 0.97),
)
),
size=guide_legend(
theme=theme(
legend_position=(0.03, 0.03),
)
)
)
+ theme(
figure_size=(15, 10),
plot_background=element_rect(fill="white"),
panel_border=element_rect(color="black"),
legend_margin=5,
legend_background=element_rect(fill="#FFFFFFBB", color="#00000022"),
axis_ticks=element_blank(),
axis_text=element_blank(),
axis_title=element_blank(),
plot_margin_top=0.2,
)
)
fig = plot2.draw()
ax = fig.get_axes()[0]
ctx.add_basemap(ax, crs=gdf.crs.to_string(), source=ctx.providers.OpenStreetMap.Mapnik)
fig |
6 replies
|
Ahoy @nimisha-18, |
0 replies
|
@nimisha-18, The winning submission has been announced here. Thank you for taking part in the contest. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Authors
Nimisha Singh
Links
[GitHub] (https://github.com/nimisha-18), [LinkedIn] (www.linkedin.com/in/nimisha-singh-859015244)
Full description
Plotnine Contest 2024
This project visualizes global disease outbreaks using Plotnine (R's visualization grammar for Python), GeoPandas, and Contextily. The map plots the locations of various disease outbreaks with color-coded points indicating the type of disease and the size representing the severity rating. The addition of a basemap from OpenStreetMap enhances the geographical context. This repository includes the code and dataset used to create the visualization, demonstrating techniques in geospatial data handling and visualization.
Code repository
https://github.com/nimisha-18/Plotnine_contest_2024
All reactions