在Python中绘制多个点而不是一个点
不知道为什么它不能产生他们所有的观点。这是我的密码:在Python中绘制多个点而不是一个点,python,matplotlib,tweepy,matplotlib-basemap,Python,Matplotlib,Tweepy,Matplotlib Basemap,不知道为什么它不能产生他们所有的观点。这是我的密码: from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener from mpl_toolkits.basemap import Basemap 我认为您可以缓存数据,然后最终将它们全部打印出来: class listener(StreamListener): x = [] y = []
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from mpl_toolkits.basemap import Basemap
我认为您可以缓存数据,然后最终将它们全部打印出来:
class listener(StreamListener):
x = []
y = []
def on_status(self, status):
if status.coordinates:
print status.coordinates
coords = status.coordinates
latitude = coords['coordinates'][0]
longitude = coords['coordinates'][1]
xt,yt = m(latitude, longitude)
self.x.append(xt)
self.y.append(yt)
return True
def plotAll(self):
m.plot(self.x, self.y, 'ro', markersize=20, alpha=.5)
Plotter = listener()
try:
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, Plotter)
twitterStream.filter(track=["justin", "bieber"])
Plotter.plotAll()
except KeyboardInterrupt, e:
plt.show()
无法使用您的特定条件和
OAuthHandler
对其进行测试,但在没有它的情况下,它在这里工作。哦,不,贾斯汀·比伯入侵了StackOverflow!D:你能提供一个最小的非工作示例,使用一些硬编码数据,这样我们就可以看到你数据的结构,而不需要我们自己使用tweepy获取数据吗?@sebix它会绘制一张地图,上面只有一个图,因为它会绘制纬度和纬度的坐标longitude@sebix我在帖子中添加了更多信息。希望这能澄清这一点。