You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GeoPandas绘图异常求助:CSV经纬度点无法正常显示

Troubleshooting Your GeoPandas Plotting Issue

Hey there! Let's figure out why your point plot isn't showing up correctly in Jupyter Notebook. I've looked over your code and there are a few common fixes that might resolve this—let's go through them one by one:

1. You're Missing a Coordinate Reference System (CRS)

GeoPandas needs to know what coordinate system your latitude/longitude values use. Since you're working with standard GPS coordinates (WGS84), you should explicitly set the CRS to EPSG:4326 when creating your GeoDataFrame. Without this, the plot might not render the points in the correct spatial context, leading to unexpected scaling or invisible points.

Fix this by updating your GeoDataFrame creation line:

df = gpd.GeoDataFrame(df, geometry='coordinates', crs="EPSG:4326")

Or if you've already created the GeoDataFrame, you can set it afterward:

df.set_crs("EPSG:4326", inplace=True)

2. Default Plot Styling Might Be Hiding Your Points

The default plot settings could make your points too small or blend into the background. Try adding styling parameters to make them more visible:

df.plot(figsize=(20,10), marker='o', color='crimson', markersize=8, alpha=0.7)
plt.title("Bike Station Locations")
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.show()

The marker, color, and markersize parameters will make your points stand out, and plt.show() ensures the plot renders properly in Jupyter.

3. Verify Your Geometry Column is Valid

Double-check that your coordinates (now geometry) column contains valid Point objects. Run this to inspect the first few entries:

print(df.geometry.head())

You should see output like <POINT (-73.985 40.748)> for each row. If any entries are None or invalid, you'll need to clean your CSV data (though you mentioned coordinates are all good, it's worth confirming!).

4. Manually Set Plot Bounds (If Needed)

Sometimes the auto-scaling of the plot might zoom out too far or focus on the wrong area. You can set explicit bounds using your data's min/max coordinates:

x_min, y_min, x_max, y_max = df.total_bounds
plt.xlim(x_min - 0.01, x_max + 0.01)  # Add a small buffer
plt.ylim(y_min - 0.01, y_max + 0.01)
df.plot(figsize=(20,10), marker='o', color='crimson', markersize=8)
plt.show()

Modified Full Code Example

Here's your code with these fixes integrated:

import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import Point

# Load CSV data
df = pd.read_csv('HRSQ12020.csv')

# Create Point objects from longitude/latitude (simplified approach)
df['coordinates'] = df.apply(lambda row: Point(row['Longitude'], row['Latitude']), axis=1)

# Convert to GeoDataFrame with explicit CRS
df = gpd.GeoDataFrame(df, geometry='coordinates', crs="EPSG:4326")

# Plot with visible styling
fig, ax = plt.subplots(figsize=(20,10))
df.plot(ax=ax, marker='o', color='crimson', markersize=8, alpha=0.7)
ax.set_title("Bike Station Locations (Q1 2020)")
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
plt.show()

Give these steps a try—most likely the missing CRS is the main culprit, but adding styling will make sure you can see your points clearly once they render.

内容的提问来源于stack exchange,提问作者Katie Morrison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 12:47:52