底图-点不使用.scatter函数绘制

问题描述

我一直在尝试寻找那些遇到类似问题但没有成功的人的各种职位。我一直在尝试在代码的注释部分中绘制出经度和纬度的位置,但是我无法使这些点出现。这是我的代码

enter image description here

web: bundle exec puma -C ./config/puma.rb
worker: bundle exec sidekiq

解决方法

您至少犯了2个错误。首先,格林威治子午线的西经应为负。选项latlon=True是错误的,因为x和y在该位置不是长/纬度,它们已经是data坐标。

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

#Set the figure size
plt.figure(figsize=(12,7))
m = Basemap(llcrnrlon=-128.4,llcrnrlat=25.8,urcrnrlon=-63,urcrnrlat=51.7)
m.shadedrelief(scale=0.5,alpha=0.6)

m.drawcoastlines()

#Important things to remember
#Atlanta/Coordinates     33.7490° N,84.3880° W
#CO                      38.8339° N,104.8214° W
#Phoenix                 33.4484° N,112.0740° W
lat = [33.75,38.84,33.45]
lon = [-84.39,-104.82,-112.1]  #west longitude
x,y = m(lon,lat)

# 2. Scatter city data with color representing employment increase and 
#    size representing housing prices increase
m.scatter(x,y,latlon=False,c='k',marker = 'o',zorder=10)
plt.show()

usa