colored plot with district direction #48
Tanvi-Jain01
started this conversation in
General
Replies: 1 comment
-
@nipunbatra , @patel-zeel CODE:hourlydata=xr.open_dataset(r'C..\daily_data.nc')
df=hourlydata.to_dataframe()
shapefile_path=r'C:\..\output .csv'
raildf = pd.read_csv(shapefile_path)
#print(raildf)
geometry = [Point(xy) for xy in zip(raildf['Longitude'], raildf['Latitude'])]
railway = gpd.GeoDataFrame(raildf, geometry=geometry)
shapefile_path = r'C:\Users\Harshit Jain\Desktop\delhiaq\Delhi\Districts.shp'
gdf_shape = gpd.read_file(shapefile_path)
unique=df[['station','latitude','longitude']].drop_duplicates()
lat = unique['latitude']
lon = unique['longitude']
geometry = [Point(x, y) for x, y in zip(lon, lat)]
stationgeo=gpd.GeoDataFrame(unique,geometry=geometry)
df = gpd.GeoDataFrame(df, geometry=geometry)
#print(df)
fig, ax = plt.subplots(figsize=(10, 10))
shapefile_extent = gdf_shape.total_bounds
plt.xlim(shapefile_extent[0], shapefile_extent[2])
plt.ylim(shapefile_extent[1], shapefile_extent[3])
num_districts = len(gdf_shape)
colors = []
for _ in range(num_districts):
# Generate random RGB values
red = random.random()
green = random.random()
blue = random.random()
color = (red, green, blue)
colors.append(color)
# Plot the districts with random colors
gdf_shape.plot(ax=ax, color=colors,edgecolor='black',alpha=0.5)
# Add labels for district names within the polygons
for idx, row in gdf_shape.iterrows():
geom = row.geometry
district_name = row["DISTRICT"]
centroid = geom.centroid
x, y = centroid.x, centroid.y
# Add the district name as a label within the polygon
ax.annotate(district_name, (x, y), ha="center", va="center")
railway.plot(ax=ax, edgecolor='black', facecolor='black',alpha=0.5,label='Railway station')
df.plot(ax=ax, edgecolor='black', facecolor='red',markersize=7*df['pm25'],label='Air station')
ax.set_aspect('equal')
plt.legend()
ax.set_axis_off()
plt.show() Explaination:The code reads data from a CSV file containing railway station information and a shapefile containing district boundaries. It creates a plot that visualizes the district boundaries using random colors for each district. Labels for district directions are added within the polygons. OUTPUT:The resulting plot provides a visual representation of district boundaries, railway stations, and air stations in an informative manner. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Colored Plot and Direction of District
@nipunbatra , @patel-zeel
Saw the above image on this site: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8137507/
It looks better with colors and also showing direction for each districts which is more informative and useful to know about the wind direction.
As the below image shows the wind direction with its speed but its hard to imagine on the map without direction, but if we know that which district falls under which direction it would be easier for us to get useful insight and enabling viewers to grasp the wind patterns and their implications more effectively.
Beta Was this translation helpful? Give feedback.
All reactions